Value types are stored in the Stack.
Examples : bool, byte, chat, decimal, double, enum , float, int, long, sbyte, short, strut, uint, ulong, ushort.
Reference types are stored in the Heap.
Examples : class, delegate, interface, object, string.
————————————————————————————————————
In C#, variables are categorized into the following types:
-
Value types
-
Reference types
-
Pointer types
Value Types
Value type variables can be assigned a value directly. They are derived from the classSystem.ValueType.
The value types directly contain data. Some examples are int, char, float, which stores numbers, alphabets, floating point numbers, respectively. When you declare an int type, the system allocates memory to store the value.
The following table lists the available value types in C# 2010:
Type | Represents | Range | Default Value |
---|---|---|---|
bool | Boolean value | True or False | False |
byte | 8-bit unsigned integer | 0 to 255 | 0 |
char | 16-bit Unicode character | U +0000 to U +ffff | ‘ |