CTS and CLS are parts of .NET CLR and are responsible for type safety within the code. Both allow cross-language communication and type safety. In this article, I would like to expose the relationship between these two.
CLS
CLS stands for Common Language Specification and it is a subset of CTS. It defines a set of rules and restrictions that every language must follow which runs under .NET framework. The languages which follow these set of rules are said to be CLS Compliant. In simple words, CLS enables cross-language integration or Interoperability.
For Example
- if you take C-Sharp and VB.net in C# each and every statement must have to end with a semicolon it is also called a statement Terminator but in VB.NETeach and every statement should not end with a semicolon(;).
Explanation of above Example
So these syntax rules which you have to follow from language to language differ but CLR can understand all the language Syntax because in.NET each language is converted into MSIL code after compilation and the MSIL code is language specification of CLR.
Common Type System (CTS) describes the datatypes that can be used by managed code. 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. The rules defined in CTS can be used to define your own classes and values.
OR we can also understand like,
In CTS, it deals with the data type. Here we have several languages and each and every language has its own data type and 1 language data type cannot be understandable by other languages but I can understand all the data types.
C# has int Data Type and VB.Net has Integer Data Type. Hence a variable declared as int in C# or Integer in vb.net, finally after compilation, uses the same structure Int32 from CTS.
Note
All the structures and classes available in CTS are common for all .NET Languages and the purpose of these is to support language independence in .NET. Hence it is called CTS.