In CSharp, data types are core fundamental elements which makes CSharp strongly typed language. This means all operation are typed checked by the compiler
for type competibility. Because CSharp is strongly typed language, you required to tell to the compiler which data type you are using in programming.
Both reference and value types are derived from the ultimate base class object.
CSharp has its own set of built in data types, which can be categories into value type and reference type. In CSharp 4 they introduced new data type called dynamic.
Value type are used to hold actual value such as 3.44 or 2884, but reference type hold reference to the value. The most commonly used reference types are string or class data type.
Each data type in CSharp has corresponding underlying .NET Common Language Runtime type. For example, the int type in CSharp maps to the System.Int32
type in the runtime.
CSharp has the following data types
Value type also known as simple type or primitive types which include boolean, byte etc. CSharp specifies specific range for each value type for example byte value type can hold value range from 0 to 255.
All value types are derived implicitly from the System.ValueType.
CSharp has a set of predefined value types.
True or False
8-bit unsigned integer
0 to 255
16-bit Unicode character
U +0000 to U +ffff
128-bit precise decimal values with 28-29 significant digits
(-7.9 x 1028 to 7.9 x 1028) / 100 to 28
64-bit double-precision floating point type
(+/-)5.0 x 10-324 to (+/-)1.7 x 10308
32-bit single-precision floating point type
-3.4 x 1038 to + 3.4 x 1038
32-bit signed integer type
-2,147,483,648 to 2,147,483,647
64-bit signed integer type
-923,372,036,854,775,808 to 9,223,372,036,854,775,807
8-bit signed integer type
-128 to 127
16-bit signed integer type
-32,768 to 32,767
32-bit unsigned integer type
0 to 4,294,967,295
64-bit unsigned integer type
0 to 18,446,744,073,709,551,615
16-bit unsigned integer type
0 to 65,535
The below example illustrate some of the above value type
In CSharp, reference type hold the address of value instead of directly to a value. The reference type is store in heap and does not have fixed size, for example string can be size form 2 bytes to all the
memory available on a system. Reference types include string, class, interfaces and delegates.
CSharp has built-in reference types as: object, dynamic, and string.