Sunday, January 4, 2009

Differences between Value And Reference Type

Starting start from very basic that Types are template that describe a set of data encapsulation and functionality.

Basically there are two kinds of types, they are

* Reference Type (Classes)
* Value Type (Structure)
The primary difference is the way variable data is accessed.
To understand it let’s go through stack and heap. All the data associated with value type are allocated on stack while a variable on reference type exists in two memory locations. The actual object data is stored on heap and a variable containing pointer (address or reference) to that object is allocated on stack.

* If an object is left without having any reference, it is subject to garbage collection. It is the
CLR which manages allocation of heap memory for objects and controls their recuperation.

Examples of value and reference types:
* Value Type Integer, Bool, Char, Structure, Enum etc.
* Reference Type Classes, Delegates, Array Types etc.

-
*1X4 USB Switchview Secure Niap Certification Approved

No comments:

Post a Comment