What is Value Type and Reference Type
Value Type : A data type is a value type if it holds a data value within its own memory space. It means the variables of these data types directly contain values.
int a = 10;
Value types are generally (not always) stored on the stack
The following data types are all of value type:
- bool
- byte
- char
- decimal
- double
- enum
- float
- int
- long
- sbyte
- short
- struct
- uint
- ulong
- ushort
Reference Type :
Unlike value types, a reference type doesn't store its value directly. Instead, it stores the address where the value is being stored. In other words, a reference type contains a pointer to another memory location that holds the data.
string data = "Hello World" ;
stored on the heap