In this article we will explain what are the data types in c# . Different between value type and reference type or how to define a value type variable and reference type variable with example:
C# is a strongly typed language. You cannot declare a variable without data types. C# provides two types of data types: Value types and Reference types.
In c# Value type variables can be assigned a value directly. Value Type variables are stored in the stack. It is derived from the class System.ValueType.
The following lists the available value types
0 to 255
-128 to 127
-2,147,483,648 to 2,147,483,647
0 to 4294967295
-32,768 to 32,767
0 to 65535
-9223372036854775808 to 9223372036854775807
0 to 18446744073709551615
-3.402823e38 to 3.402823e38
-1.79769313486232e308 to 1.79769313486232e308
Unicode symbols used in text
True or false
±1.0 × 10e−28 to ±7.9 × 10e28
For Example Value Type :
int i = 123;
The reference data type does not store the actual data in a variable, but it is store a reference to the variables. Reference Type variables are stored in the heap , the reference types can refer to a memory location. If the data in the memory location is changed by one of the variables, the other variable automatically reflects this change in value.
For example reference types: object, dynamic, and string.
dynamic a = 100;
string b = "aditya";
object c = 500;