What is Common Type System (CTS) In .Net ?

Shivani Nalawade
3 min readSep 4, 2020

.NET is language-agnostic, which allows programmers to write code in different languages (which can be compiled to IL), and that code can interact with other code written in different languages.

  • Common Type System (CTS) describes the datatypes that can be used by managed code.
  • The CTS defines the predefined data types available in IL so that all languages that target the .NET Framework can produce compiled code ultimately based on these types.
  • It provides an object oriented model & also provides a library that contains primitive data types.
  • CTS defines how these types are declared, used and managed in the runtime. It facilitates cross-language integration, type safety, and high-performance code execution.
  • CTS deals with the data type. So here we have several languages and each and every language has its own data type and one language data type cannot be understandable by other languages but .NET Framework language can understand all the data types.

For example, C# has an int data type and VB.NET has Integer data type. Hence a variable declared as an int in C# and Integer in VB.NET, finally after compilation, uses the same structure Int32 from CTS.

Examples of CTS

The common type system performs the following functions:

  1. It enables cross-language integration, type safety, and high-performance code execution.
  2. It provides an object-oriented model for the implementation of many programming languages.
  3. It defines rules that every language must follow which runs under .NET FRAMEWORK It ensures that objects written in different .NET languages like C#, VB.NET, F# etc. can interact with each other.

The CTS defines the following types:

  1. Reference type: Reference types are allocated on the heap and stores a reference to the value’s memory address.
  2. Value type: Value types are allocated on the stack and directly contain their data.

Explanation with a real example: To explain the CTS I will create a console applications like:

C#

Step 1: Create the first Console application in C# named “ConsoleApp_CS”.

Step 2: Create a variable of int type and assign a value like 10 and build the application that generates the .exe file in the bin folder of the project.

int i = 10;

Step 3: Again open the “IL Disassembler” by selecting the Start menu then “Microsoft Visual Studio ” -> “Microsoft Windows SDK Tools”.

Step 4: Open your .exe file that exists in the bin folder of the project via “File” -> “Open”.

Step 5: Now double-click on the “Main” method that shows the following window where you can see your variable “i” that was an int type and now it converts into “int32”.

Conclusion

I hope now you have an understanding of the Common Type System and the real example that converts the int of C# into int32.

I hope this guide has been helpful for you 😃!!!

--

--