Value Types and Reference Typesare stored in defferent palces in memory;value types are stored in an area known as the stack, and reerence types are stored in an area known as the managed heap.It's important to be aware of whether a type is a value type or a reference type because of the different effect each assignment has.
In C#, basic data types like bool and long are value types.This means that if you declare a bool variable and assign it the value of another bool variable, you will have two separate bool values in memory..Later if you change the value of the original bool variable, the value of the second bool variable does not change. These types are copied by value.
In constract, most of more complex C# data types, including classes that you yourself declare, are reference types. Tyey are allocated upon the heap, have lifetimes that can span multipile function calls and can be accessed throuth one or several aliases. |