.NET Architecture—Common Type System
Microsoft .NET Framework, ASP.NET, Visual C# (CSharp, C Sharp, C-Sharp) Developer Training, Visual Studio
| CSharp-Online.NET:Articles |
| .NET Articles |
| © 2006 Wiley Publishing, Inc. |
Common Type System
This data type problem is solved in .NET through the use of the Common Type System (CTS). The CTS defines the predefined data types that are available in IL, so that all languages that target the .NET Framework will produce compiled code that is ultimately based on these types.
For the previous example, Visual Basic 2005’s Integer is actually a 32-bit signed integer, which maps exactly to the IL type known as Int32. This will therefore be the data type specified in the IL code. Because the C# compiler is aware of this type, there is no problem. At source code level, C# refers to Int32 with the keyword int, so the compiler will simply treat the Visual Basic 2005 method as if it returned an int.
The CTS doesn’t merely specify primitive data types but a rich hierarchy of types, which includes welldefined points in the hierarchy at which code is permitted to define its own types. The hierarchical structure of the Common Type System reflects the single-inheritance object-oriented methodology of IL, and resembles Figure 1-1.
The following table explains the types shown in Figure 1-1.
| Type | Meaning |
| Type | Base class that represents any type. |
| Value Type | Base class that represents any value type. |
| Reference Types | Any data types that are accessed through a reference and stored
on the heap. |
| Built-in Value Types | Includes most of the standard primitive types, which represent numbers, Boolean values, or characters. |
| Enumerations | Sets of enumerated values. |
| User-defined Value Types | Types that have been defined in source code and are stored as value types. In C# terms, this means any struct. |
| Interface Types | Interfaces. |
| Pointer Types | Pointers. |
| Self-describing Types | Data types that provide information about themselves for the benefit of the garbage collector (see the next section). |
| Arrays | Any type that contains an array of objects. |
| Class Types | Types that are self-describing but are not arrays. |
| Delegates | Types that are designed to hold references to methods. |
| User-defined Reference Types | Types that have been defined in source code and are stored as reference types. In C# terms, this means any class. |
| Boxed Value Types | A value type that is temporarily wrapped in a reference so that it can be stored on the heap. |
We won’t list all of the built-in value types here. In C#, each predefined type recognized by the compiler maps onto one of the IL built-in types. The same is true in Visual Basic 2005.
|

