2. Common Type System
The common type system defines how types are declared,
used, and managed in the common language runtime, and
is also an important part of the runtime's support for cross-
language integration.
The common type system performs the following
functions
Establishes a framework that helps enable cross-language
integration, type safety, and high-performance code
execution.
Provides a library that contains the primitive data types
(such as Boolean, Byte, Char, Int32, and UInt64) used in
application development.
3. Value types and Reference types
C# divides the world of types into value types and reference
types. Value types are created on the stack. All the intrinsic
types (int ,long) are value types and thus are created on the
stack.
Objects on the other hand, are reference types. Reference
types are created on an undifferentiated block of memory
known as the heap.
Structs, types such as int, float, long etc are value types.
Strings are reference types.
Memory of reference types is claimed by garbage collector.
5. Value Types
Value type variables can be assigned a value directly.
They are derived from the class System.ValueType.
The value types directly contain data. Some examples
are int, char, and float, which stores numbers,
alphabets, and floating point numbers, respectively.
When you declare an int type, the system allocates
memory to store the value.
6. C# Memory Range
int 4 bytes –2147483648 to 2147483647
long 8 bytes –9223372036854775808 to 9223372036854775807
byte 1 byte 0 to 255
float 4 bytes –1.5x10-45 to 3.4 x x1038
double 8 bytes –5.0x10-324 to 1.7x10308
char 2 bytes Unicode characters
boolean 1 byte True or false
Predefined Data Types
7. Reference Types
The Reference type variable is such type of variable in
C# that holds the reference of memory address instead
of value.
Reference
Type
Class
Type
Type
name
Object String
Interface
Type
Array
Delegate
Type
8. For example, consider following string variable:
string s = "Hello World!!";
The following image shows how the system allocates the
memory for the above string variable.
Memory allocation for Reference typeAs you can see in the
above image, the system selects a random location in
memory (0x803200) for the variable 's'. The value of a
variable s is 0x600000 which is the memory address of the
actual data value. Thus, reference type stores the address of
the location where the actual value is stored instead of
value itself.