codingstuff.io
ExploreTutorialsProblemsCS Subjects
Get Started
ExploreTutorialsProblemsCS Subjects
Get Started
codingstuff.io

Master the art of building software through interactive tutorials, real-world problems, and guided projects.

Pune, Maharashtra, India

codingstuffmail@gmail.com

Product

  • Explore
  • Tutorials
  • Problems
  • CS Subjects

Company

  • About
  • Contact
  • Privacy Policy
  • Terms & Conditions
  • Sitemap

© 2026 codingstuff.io. All rights reserved.

Built with ❤️ for developers everywhere

/
/
All Tutorials
🔷

C# Programming

4 / 60 topics
1Getting Started with C#2C# Syntax3Variables in C#4Data Types in C#5Operators in C#
Tutorials/C# Programming/Data Types in C#
🔷C# Programming

Data Types in C#

Updated 2026-05-15
10 min read

Data Types in C#

Introduction

Welcome to the section on Data Types in C#. Understanding data types is fundamental to programming in any language, as they define the kind of values that can be stored and manipulated. In this tutorial, we will explore various data types available in C#, including both primitive (or value) types and reference types.

Data types determine the range of values a variable can hold and the operations that can be performed on it. C# is a statically typed language, meaning that the type of a variable must be known at compile time. This helps catch errors early in the development process.

Concept

Primitive Data Types

Primitive data types are the basic building blocks for all other data types in C#. They include:

  1. Integer Types: Used to store whole numbers.

    • int: Represents 32-bit signed integers.
    • long: Represents 64-bit signed integers.
    • short: Represents 16-bit signed integers.
    • byte: Represents 8-bit unsigned integers.
  2. Floating-Point Types: Used to store decimal numbers.

    • float: Represents single-precision floating-point numbers.
    • double: Represents double-precision floating-point numbers.
  3. Decimal Type: Used for high precision calculations, such as financial computations.

    • decimal: Represents 128-bit signed integers with a fixed scale and precision of up to 28-29 digits.
  4. Character Types: Used to store individual characters.

    • char: Represents a single Unicode character.
  5. Boolean Type: Used to store true or false values.

    • bool: Represents Boolean values (true or false).

Reference Data Types

Reference data types refer to objects and are stored on the heap. They include:

  1. Class Types: User-defined reference types that can contain fields, methods, properties, etc.
  2. Interface Types: Define a contract for classes, structs, and enums.
  3. Array Types: Used to store collections of elements of the same type.
  4. String Type: Represents sequences of characters.

Examples

Let's dive into some practical examples to illustrate these data types in action.

Integer Types

CodeBlock language="csharp">
{`int number = 10;
long bigNumber = 123456789012345;
short smallNumber = -32768;
byte unsignedByte = 255;`}
</CodeBlock>

<Tip variant="info">Note that `byte` is the only unsigned integer type in C#.</Tip>

### Floating-Point Types

```csharp
CodeBlock language="csharp">
{`float pi = 3.14f;
double precisePi = 3.141592653589793;`}
</CodeBlock>

<Tip variant="info">The `f` suffix is used to denote a float literal.</Tip>

### Decimal Type

```csharp
CodeBlock language="csharp">
{`decimal highPrecisionNumber = 0.1m + 0.2m;
Console.WriteLine(highPrecisionNumber == 0.3m); // True`}
</CodeBlock>

<Tip variant="info">The `m` suffix is used to denote a decimal literal.</Tip>

### Character and Boolean Types

```csharp
CodeBlock language="csharp">
{`char letter = 'A';
bool condition = true;`}
</CodeBlock>

### String Type

```csharp
CodeBlock language="csharp">
{`string greeting = "Hello, World!";
Console.WriteLine(greeting.Length); // Outputs 13`}
</CodeBlock>

## What's Next?

In the next section, we will explore operators in C#, which are used to perform operations on variables and values. Understanding operators is crucial for performing arithmetic calculations, comparisons, and more.

Stay tuned!

PreviousVariables in C#Next Operators in C#

Recommended Gear

Variables in C#Operators in C#