C# programs run on .NET, a virtual runtime system that calls the Common Language Runtime (CLR) and a set of class libraries. The CLR environment is Microsoft’s implementation of the Common Language Infrastructure (CLI), an international standard. The CLI is the basis for creating runtime and development environments in which languages and libraries work transparently with each other.
Source code written in C# is compiled into an intermediate language (IL) that conforms to the CLI specifications. The IL code and resources, including bitmaps and strings, are stored in an assembly, usually with a .dll extension. An assembly contains a manifest with information about the types, version, language, and regional parameters for that assembly.
When a C# program runs, the assembly is loaded into the CLR environment. The CLR environment performs JIT compilation from IL code into machine language instructions. The CLR environment also performs other operations such as automatic garbage collection, exception handling, and resource management. The code executed by the CLR environment is sometimes called “managed code.” “Unmanaged code” is compiled into a platform-specific machine language.
Providing interoperability between languages is a key feature of .NET. The IL code created by the C# compiler conforms to the Common Type Specification (CTS). IL code created from C# code can interoperate with code created from the .NET versions of F#, Visual Basic, and C++. There are more than 20 other languages compatible with CTS. One assembly can contain several modules written in different .NET languages, and all types can reference each other as if they were written in the same language.
In addition to runtime services, .NET also includes extended libraries. These libraries support many different workloads. They are organized into namespaces that provide a variety of useful features, from file input and output operations to string management and XML parsing, to web application platforms to Windows Forms controls. Typically, C# applications make heavy use of the .NET class library for typical tasks.