Common Type System (CTS) is the powerful unified way of making all types as objects. Object is the base class for any type in C#. Object is reference type though.
Here is the quick snap of the CTS:
C# types are broadly classified as: Value type & Reference type. This classification is based on size of types. Value types basically stores value at the given memory location (mostly in stack) whereas Reference types stores data on managed heap.
Value Types:
int
float
char
struct
Reference Types:
.NET framework class library
User defined classes, interfaces, delegates, events, array, string
C# design goal is to UNIFY every types into OBJECTS. Hence, all types are derived from System.Object. When we assign any value into object, the conversion happens IMPLICIT and the process is called BOXING.
Whereas when we try to pull data from boxed object into particular type, we need to type-cast the data into the container type which is called UN-BOXING. The type casting is much required here as the object type would have assigned any other value by any other thread.
Here is the quick snap of the CTS:
C# types are broadly classified as: Value type & Reference type. This classification is based on size of types. Value types basically stores value at the given memory location (mostly in stack) whereas Reference types stores data on managed heap.
Value Types:
int
float
char
struct
Reference Types:
.NET framework class library
User defined classes, interfaces, delegates, events, array, string
C# design goal is to UNIFY every types into OBJECTS. Hence, all types are derived from System.Object. When we assign any value into object, the conversion happens IMPLICIT and the process is called BOXING.
Whereas when we try to pull data from boxed object into particular type, we need to type-cast the data into the container type which is called UN-BOXING. The type casting is much required here as the object type would have assigned any other value by any other thread.

No comments:
Post a Comment