Getting Familiar with the Common Type System

In this post on Getting Familiar with the Common Type System, you will learn an important component of the .NET Framework. This component is called the Common Type System or CTS. In essence, the Common Type System forms the basis of Data Types available in .NET Programming languages.

In general, the .NET framework provides interoperability among the applications developed in different programming languages, provided the .NET Framework supports them. In other words, the components of an application developed under different .NET languages are compatible with each other. As a matter of fact, CTS along with CLS (Common Language System) provides language interoperability.

Basically, the Common Type System or CTS offers a set of data types that are common to all .NET programming languages. As a result, when we compile the code written in one .NET language it automatically becomes compatible with the compiled code of another .NET language. Given these points, we can say that the data types are the basis for the Common Type System in .NET Framework. In order to Getting familiar with the Common Type System, we need to understand the data types that CTS offers.

Data Types in CTS

Basically, there are two broad categories of Data Types under CTS – the Value Type and the Reference Type. Additionally, the root Type of all data types under CTS is System.Object. Hence, every type derives from the root Type known as Object defined in the System namespace. It must be remembered that although all reference types such as classes and interfaces are inherited directly from the Object class. However, the value types such as Int32 or Double inherit from the ValueType class which in turn, is extended from the Object class. In addition, the value types get memory allocation from the stack whereas the reference types get memory allocation from the heap.

Value Types

All the Primitive Data Types are Value Types in CTS. The numeric types are IByte, Int16, Int32, Int64, UInt16, UInt32, UInt64, Single, Double, and Decimal. Apart from the numeric types, the Common Type System also specifies the non-numeric types such as Char and Boolean. The Char data type has a size of 16-bits and takes character values. Whereas, the Boolean type takes a value of true or false. Also, when the methods take value types as parameters, pass by value mechanism is used. Specifically, CTS also defines enumerations, which are inherited from System.Enum, as given below.

 enum BookPrice: ushort
        low = 300,
        medium = 750,
        high = 1250

CTS also specifies a custom type called Structure, which we can define by using several other types. In .NET, a structure can have fields, methods, and constructors, as given below.

 struct Book
        String title;
        int price;
        public Book(String title, int price)
            this.title = title;
            this.price = price;
        public void show()
            Console.WriteLine("Title: " + title + " Price: " + price);

Reference Types

Reference types are dynamically allocated. Basically, there are four reference types in .NET – class, Array, Interface, and delegate. The reference types are passed by reference.

Considering the reference types, a class allows us to work with real-world entities called objects, which have specified attributes and behavior. Of course, we have other reference types also such as interface, which allow us to provide the decalation of methods without implementation details. In addition, the Delegates specify reference to methods and Arrays represent a collection of values all belonging to the same type.

Common Type System (CTS)
Common Type System (CTS)

Benefits of Common Type System

  • CTS empowers the development for cross language execution
  • Provides support for implementing more languages under .NET Framework
  • Offers a library of the classes representing the fundamental data types
  • Supports cross-language integration by making it possible for extending classes written in other .NET languages.

To sum up, the Common Type system gives .NET developers a common way to describe all supported types. It makes the application development in .NET much easier and productive with a greater scope of reusability.

Related Topics

Just-In-Time (JIT) CompilerAssemblies in .NETCompilation and Execition Plan of .NET

Leave a Comment

Your email address will not be published. Required fields are marked *