Wednesday, 28 December 2011

What is Value Types and Reference types and difference between boxing and Unboxing

A Type is defined as a set of data and the operations performed on them. CSharp is a strongly typed language. The CSharp type system contains three Type categories. They are Value Types , Reference Types and Pointer Types . The Value Types store the data while the Reference Types store references to the actual data. Pointer Types variable use only in unsafe mode. The Value Types derived from System.ValueType and the Reference Types derived from System.Object .

The main difference between Value Types and Reference Types is that how these Types store the values in memory. Common Language Runtime (CLR) allocates memory in Stack and the Heap . A Value Type holds its actual value in memory allocated on the Stack and Reference Types referred to as objects, store references to the actual data. In C# it is possible to convert a value of one type into a value of another type . The operation of Converting a Value Type to a Reference Type is called Boxing and the reverse operation is called Unboxing.

No comments:

Post a Comment