In this article we will learn about Value type vs Reference type.
Data Type system of CLR which is common to all programming languages of .Net is know as Common Type System(CTS).
This common type system is devided in two categories.
1. Value types
2. Reference types
The data types which stores the data directly into their memory locations is known as value types.
The date types which do not store the data directly into their memory locations rather refers to other memroty locations is known as reference types.
Here is the difference between Value and Reference types:
VALUE TYPES:
- Store the value directly into their Memory Locations.
- Memory is allotted at compile time.
- Memory allocation is Made with in the Stack i.e. in contiguous Memory Locations.
- CLR Does not provide automatic memory management.
REFERENCE TYPES:
- Do not store the values directly in to their memory locations, rather refers to other memory location where value is stored.
- Memory is allotted at run time
- Memory allocation is made with in the Heap i.e. Random Memory Locations.
- CLR provides automatic memory management.