Home »
C# Tutorial
C# Data Types
In this tutorial, we will learn about the various data types in C# programming language?
Last updated : April 04, 2023
What are Data Types?
Data types define what and how data should be stored and used. C# is a type-safe language. Variables are declared as being of a particular type, and each variable is constrained to hold only values of its declared type In C#.
Types of C# Data Types
There are two types of data types are used,
- Value Types
A variable of value types directly contains only an object with the value.
- Reference types
A variable of reference type directly contains a reference to an object. Another variable may contain a reference to the same object.
We can also define our own value types by declaring enumerations or structures.
C# Predefined Data Types
The data types which are predefined in the C# compiler, these are also referred to as Basic Data Type of C#. The value range (minimum and maximum values) and size of these data types are predefined; anyone can not modify the range and size of these data types.
Most Common C# Data Types
The most common data types are:
Data Type |
Size (in bytes) |
Description (Range) |
int | 4 bytes | -2,147,483,648 to 2,147,483,647 |
long | 8 bytes | -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 |
float | 4 bytes | Used to store fractional numbers up to 6-7 decimal digits |
double | 8 bytes | Used to store fractional numbers up to 15 decimal digits |
bool | 1 bit | true or false values |
char | 2 bytes | Used to store a single character |
string | 2 bytes per character | Used to store a string (sequence of characters) |
Here is the list of basic/predefined C# data types with type, size, range etc.
Example of Value Types
Example of Value Types is: int A = 50; here variable A hold value 50 that can be used in program.
Example of Reference Types
We can define new reference types class, interface, and delegate declarations.
object ABC = new object();
ABC.myValue = 50;