Value Type vs Reference Type in C#


Value Type and Reference, both are types in C# −

Value Type

Value type variables can be assigned a value directly. They are derived from the class System.ValueType. The value types directly contain data. When you declare an int type, the system allocates memory to store the value.

Value Type variables are stored in the stack.

Examples are int, char, and float, which stores numbers, alphabets, and floating point numbers, respectively.

Reference Type

It refers to a memory location. Using multiple variables, the reference types can refer to a memory location. If the data in the memory location is changed by one of the variables, the other variable automatically reflects this change in value.

Reference Type variables are stored in the heap.

Example of built-in reference types are −

  • object
  • dynamic
  • string

Updated on: 21-Jun-2020

5K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements