What is the difference between reference type and value type?

0 votes
196 views
Shikhar Arora asked 06-Dec-2019 in Database by Shikhar Arora

What is the difference between reference type and value type

1 Answer

0 votes
Rahul Roi answered 15-Dec-2020 by Rahul Roi

What is the difference between reference type and value type?

The Value Type

The value-type variables can be assigned a value directly. These are derived from the class System.ValueType. The value types directly contain data. If you declare an int type, the system allocates memory to store the value.
The Value Type variables are stored in the stack.
These are examples like :-
  • Int
  • char
  • float
which stores numbers, alphabets, and floating point numbers, respectively. 
What is the difference between reference type and value type?
Reference Type 
That refers to a memory location. The using multiple variables, the reference types can refer to a memory location. When the data in the memory location is changed by one of the variables, the other variable automatically reflects this change in value.
The Reference Type variables are stored in the heap.
Example of built-in reference types are − 
  • object 
  • dynamic
  • string

Read More Technical content :- MindStick Forum