C# 7 and .NET Core 2.0 High Performance
上QQ阅读APP看书,第一时间看更新

Understanding MSIL, CLI, CTS, and CLS

When we build our project, the code is compiled into the Intermediate Language (IL), also known as Microsoft Intermediate Language (MSIL). MSIL is compliant with the  Common Language Infrastructure (CLI), where CLI is the standard that provides a common type system and a language specification, respectively known as the Common Type System (CTS) and Common Language Specification (CLS).

The CTS provides a common type system and compiles the language-specific types into the compliant data types. It standardizes all the .NET languages' data types to a common data type for language interoperability. For example, if the code is written in C#, it will be converted to the specific CTS.

Suppose we have two variables, defined in the following code fragment using C#:

class Program 
{ 
  static void Main(string[] args) 
  { 
    int minNo = 1; 
    long maxThroughput = 99999; 
  } 
} 

On compilation, the compiler generates the MSIL into an assembly that will be available through the CoreCLR to perform the JIT and convert it into the native machine code. Note that the int and long types are converted to the int32 and int64 respectively:

It is not necessary for every language to comply completely with the CTS, and it can support the smaller footprint of the CTS, too. For example, when VB.NET was first released in .NET Framework, it only supported the signed integer data types, and there was no provision to use unsigned integers. With later versions of .NET Framework, and now with .NET Core 2.0, we can use all managed languages, such as C#, F#, and VB.NET, to develop applications and easily reference any project's assembly.