| Start |
|---|
| Value types in use Value types simply contain a value. All value types are derived from the System.ValueType (opens new window) class, and this includes most of the built in types. When creating a new value type, the an area of memory called the stack is used. The code below demonstrates a value type being assigned to a new variable. A struct is being used as a convenient way to create a custom value type (the System.ValueType class cannot be otherwise extended). The important thing to understand is that when assigning a value type, the value itself copied to the new variable, meaning we have two distinct instances of the object, that cannot affect each other. |
| Reference types in use Reference types are comprised of both a reference to a memory area, and a value stored within that area. All reference types are stored on what is known as the heap. In addition to the memory space required for the instance itself, additional space is required to store the reference itself, along with additional temporary information required by the .NET CLR. The code below demonstrates a reference type being assigned to a new variable. In this instance, we are using a class, all classes are reference types (even if static). When a reference type is assigned to another variable, it is the reference to the object that is copied over, not the value itself. This is an important distinction between value types and reference types. The implications of this are that we now have two references to the same object. RemarksIt's worth noting that on declaring a reference type, its initial value will be |
Read Article
https://develop.horje.com/learn/1434/reference