Common type system
What is CTS (Common type system)?
This describes a set of types that can be used in different .NET languages in common.
The CTS Defines How Types are Declared, Used and Managed in Common Language Runtime.
This is also an important part of Runtimes support for cross-language integration.
It is a (CTS) ensures that objects are written in different .NET languages because they can interact with each other.
For communication between programs written in any .NET language, the types have to be compatible on the basic level.
This is a formal type system implemented by CLR
About 20 .NET languages carefully investigated Some of them are APL, C#, C++, COBOL, Visual Basic, Perl, Java, and Smalltalk.
Designed for Object-Oriented, Procedural and Functional Languages, In roughly that order:
- Is it useful?
- Is it necessary?
- Is it important?
FUNCTIONS OF CTS
To establish a framework because it helps to enable cross-language integration.
Provide an object-oriented model that supports the complete and implementation of so many programming languages.
Define rules that languages must follow, as it helps to ensure that objects written in different languages can interact with each other.
It provides a library that contains the primitive data types(such as Boolean, byte, char, and int32, etc) used in application development.
This allows all languages to share base data types.
CTS also specifies the rules for type visibility and access to the members of a type.
CLASSIFICATION OF CTS
This CTS (Common Type System) can be classified into two general categories: VALUE Type and REFERENCE Type.
VALUE Type: These types contain their data directly and their objects are allocated on the stack. Value types can be built-in, user-defined and enumerations.
Reference Type: These types contain the reference of the data’s memory address and are allocated on the heap because can be an array type, class type, and interface type.
Value types include data types such as Uint16, Uint32, Uint64, boolean, enum, structure, typedef, char, bytes, int16, int32, single and double.
Dim I as Integer
Dim cs as String
Reference type includes data types such as array, class, pointers and interface.
Dim a,b,c as Integer
Public sub sum()
On Button_click we create object of this class as:-
Protected Sub Button_click(……)
Dim ob as New first
Storage of Value Type and Reference Type
value sorts area unit keep in Stack memory, which is quick however restricted in size.
Refer types, which are stored in Heap memory, which is slower but larger.
Value sorts are all fairly little – they do not use a lot of memory. The numeric sorts are all price sorts, and that they do not take up a lot of sizes:
Byte – 1 byte
Short – 2 bytes
Integer – 4 bytes
Long – 8 bytes
Single – 4 bytes
Double – 8 bytes
Decimal – 16 bytes
Reference types are Objects. They live on the heap. But the important part is that variables still point to something on the stack. That something is a reference to the heap. You can think of it as the heap address where the object is stored.
Value Type v/s Reference Type
The most important difference between value type and Reference types is how types are treated by the CLR.
Instances of value types are automatically cleaned up when the variable goes out of scope.
Therefore space occupied by reference type variables is made free by Garbage Collector.
Variables that are declared as a value type have their own copy of data, and hence any operation on one variable does not affect the other variable.
Whereas the variable that is declared as reference types always point to some another object, and hence any operation on one variable affects the same instance referred to by another variable.