Data Types in C#

Data Types in C#

C# basically has two data types:

  1. Value Type

  2. Reference Type     

All types are objects in the CTS and they are derived from System.Object.

Value type directly hold actual data. Value type is allocated to stack. Assignment of value type variable creates another copy of value.Value types include simple types like char, int, and float, enum types, and struct types.The scope of the variable is from the declaration till the end of the block in which it is declared

Declaration syntax of value type:

Datatype variable;

Ex: int intCount;

      int intRecordNumber = 10;

Reference type does not directly hold actual data. It contains reference to actual data. Reference type is allocated to heap. Assignment of reference type variable creates another copy of reference.Reference types include class types, interface types, delegate types, and array types.

Declaration syntax of reference type:

Datatype variablename = new Datatype();

Leave a Reply