← Back to Articles         
C# Data Types and Type Differences

C# Data Types and Type Differences

Published on 12 Oct 2026     6 min read C#
Data Types, Variables & Operators
 

C# Data Types and Type Differences

1. 🔴 What are the different data types available in C#?

Data types define what kind of value a variable can store, such as numbers, text, characters, or Boolean values.

C# data types are mainly classified into three categories:

  1. Value Types

  2. Reference Types

  3. Pointer Types

1. Value Types

Value types directly contain their data.

Common Value Types:

Data Type

Description

Example

int

Integer numbers

100

long

Large integer numbers

10000000000L

float

Single-precision decimal numbers

10.5f

double

Double-precision decimal numbers

10.5

decimal

High-precision decimal numbers

10.5m

bool

True or false

true

char

Single UTF-16 code unit

'A'

byte

Unsigned integer from 0 to 255

255

short

Small integer

100

struct

User-defined value type

struct Employee

enum

Named constants

enum Status

Example:

int age = 25;
double salary = 45000.50;
bool isActive = true;
char grade = 'A';

2. Reference Types

Reference type variables hold references to objects rather than containing the object's data directly.

Common Reference Types:

Data Type

Description

Example

string

Text

"John"

class

User-defined reference type

Employee

object

Base type of all C# types

object obj

array

Collection of elements

int[] numbers

interface

Defines a contract

IEmployeeService

delegate

References methods

Action

record class

Reference type with value-based equality

record Employee

Example:

string name = "John";

int[] numbers = { 10, 20, 30 };

Employee emp = new Employee();

3. Pointer Types

Pointer types store memory addresses and are primarily used in unsafe code.

Example:

unsafe
{
    int number = 100;
    int* ptr = &number;

    Console.WriteLine(*ptr); // 100
}

Pointer code requires unsafe compilation to be enabled.

Data Type Classification

C# Data Types
      |
      |----------------------|
      |          |           |
      v          v           v
 Value Types  Reference    Pointer
                 Types      Types
      |          |           |
      v          v           v
    int        string       int*
    long       class        char*
    float      object
    double     array
    decimal    interface
    bool       delegate
    char
    struct
    enum

Key Points

  1. Value types directly contain their data.

  2. Reference types store references to objects.

  3. Pointer types are used in unsafe programming.

  4. int, long, float, double, and decimal are value types.

  5. string, class, and array are reference types.

  6. All C# types ultimately derive from System.Object.

Interview Answer: C# data types are mainly classified into value types, reference types, and pointer types. Value types contain their data directly, reference types refer to objects, and pointer types store memory addresses.

 

2. 🔴 What is the difference between int, long, float, double, and decimal?

These are numeric data types used to store integer and fractional numbers.

The main differences are their size, range, precision, and usage.

Numeric Data Types Comparison

Data Type

Size

Precision / Range

Example

int

4 bytes

−2.14 billion to +2.14 billion

100

long

8 bytes

Approximately ±9.22 quintillion

10000000000L

float

4 bytes

~6–9 significant digits

10.5f

double

8 bytes

~15–17 significant digits

10.5d

decimal

16 bytes

28–29 significant digits

10.5m

1. int – Integer

Used to store whole numbers without decimal values.

int age = 25;
int employeeCount = 100;

Usage: Age, quantity, count, and identifiers within its range.

2. long – Large Integer

Used when the number exceeds the range of int.

long population = 10000000000L;

Usage: Large counters, large integer IDs, and population values.

3. float – Single-Precision Floating Point

Used to store fractional numbers where lower precision is acceptable.

float temperature = 36.5f;

Usage: Graphics, gaming, and memory-sensitive numerical calculations.

4. double – Double-Precision Floating Point

Used to store fractional numbers with higher precision than float.

double distance = 1250.56789;

Usage: Scientific calculations, measurements, and general floating-point calculations.

5. decimal – High-Precision Decimal

Used when decimal precision is important, especially for financial calculations.

decimal salary = 45000.75m;
decimal amount = 1250.50m;

Usage: Banking, salary calculations, prices, and financial transactions.

Why Use decimal Instead of double for Money?

Example:

double a = 0.1;
double b = 0.2;

Console.WriteLine(a + b == 0.3); // False

This happens because double uses binary floating-point representation, which cannot represent many decimal fractions exactly.

Using decimal:

decimal a = 0.1m;
decimal b = 0.2m;

Console.WriteLine(a + b == 0.3m); // True

decimal can represent these particular decimal values exactly, making it more suitable for financial calculations. Rounding rules are still necessary in real financial systems.

Key Points

  1. int stores whole numbers up to approximately 2.14 billion.

  2. long stores larger whole numbers.

  3. float provides lower floating-point precision.

  4. double provides higher floating-point precision than float.

  5. decimal is preferred for monetary calculations.

  6. Use f for float, m for decimal, and optionally L for long.

Interview Answer: int and long store whole numbers, whereas float, double, and decimal store fractional numbers. float has lower precision, double has higher binary floating-point precision, and decimal is preferred for financial calculations.

 

3. 🔴 What is the difference between string and char?

In C#, char represents a single UTF-16 code unit, whereas string represents a sequence of UTF-16 code units used to store text.

1. char Data Type

The char data type is used to store a single character such as a letter, digit, or symbol that fits in one UTF-16 code unit.

Example:

char grade = 'A';
char digit = '5';

Console.WriteLine(grade); // A

Important: char uses single quotes (' ').

2. string Data Type

The string data type is used to store text containing zero or more characters.

Example:

string name = "John";
string message = "Welcome to C#";

Console.WriteLine(name); // John

Important: string uses double quotes (" ").

Difference Between string and char

char

string

Value type

Reference type

Represents one UTF-16 code unit

Represents a sequence of UTF-16 code units

Uses single quotes

Uses double quotes

Fixed size of 2 bytes

Length varies

Example: 'A'

Example: "Apple"

Mutable variable value

Immutable string object

Simple Example

char letter = 'A';
string word = "Apple";

Console.WriteLine(letter); // A
Console.WriteLine(word);   // Apple

Can We Convert char to string?

Yes.

char letter = 'A';

string result = letter.ToString();

Console.WriteLine(result); // A

Can We Access a Character from a String?

Yes, using an index.

string name = "John";

char firstLetter = name[0];

Console.WriteLine(firstLetter); // J

Key Points

  1. char is a value type, whereas string is a reference type.

  2. char uses single quotes; string uses double quotes.

  3. char occupies 2 bytes.

  4. A string can contain zero or more UTF-16 code units.

  5. Strings are immutable in C#.

  6. A Unicode character outside the Basic Multilingual Plane may require two char values (a surrogate pair).

Interview Answer: char is a value type that represents a single UTF-16 code unit, whereas string is an immutable reference type used to store text.

 

Quick Interview Revision

Concept

Key Point

Value Types

Directly contain data

Reference Types

Hold references to objects

Pointer Types

Store memory addresses

int

4-byte integer

long

8-byte integer

float

4-byte floating-point number

double

8-byte floating-point number

decimal

16-byte decimal number, preferred for money

char

Single UTF-16 code unit, value type

string

Immutable text, reference type

Important Interview Tip: For .NET developer interviews, remember these three distinctions: value vs reference types, double vs decimal, and char vs string. These are frequently tested C# fundamentals.

← Back to Articles