1 - What is the Common Language Runtime (CLR)?
CLR is the Virtual Machine of the .NET Framework. It is responsible for managing the execution of .NET programs regardless of any .NET programming language (C#, F#, VB). Internally, CLR implements the VES (Virtual Execution System) which is defined in the Microsoft’s implementation of the CLI (Common Language Infrastructure).
2 - What is .NET Standard?
The .NET Standard is a formal specification of .NET APIs that are intended to be available on all .NET implementations. The motivation behind the .NET Standard is establishing greater uniformity in the .NET ecosystem.
The .NET Standard enables the following key scenarios:
Defines a uniform set of BCL APIs for all .NET implementations to implement, independent of workload.
Enables developers to produce portable libraries that are usable across .NET implementations, using this same set of APIs.
Reduces or even eliminates conditional compilation of shared source due to .NET APIs, only for OS APIs.
Having a standard solves the code sharing problem for .NET developers by bringing all the APIs that you expect and love across the environments that you need: desktop applications, mobile apps & games, and cloud services.
3 - What's the difference between SDK and Runtime in .NET Core?
SDK - Installs the necessary libraries, tools and the compiler to build .NET applications.
Runtime - Installs the minimal required libraries and the CoreCLR to run .NET applications.
4 - What is Just-In-Time (JIT) Compiler in .NET?
Just-In-Time compiler (JIT) is a part of CLR in .NET. A language-specific compiler converts the source code to the intermediate language. This intermediate language is then converted into machine code by the Just-In-Time (JIT) compiler. This machine code is specific to the computer environment that the JIT compiler runs on. There are 3 types of JIT:
Pre-JIT Compiler: All the source code is compiled into the machine code at the same time in a single compilation cycle using the Pre-JIT Compiler. This compilation process is performed at application deployment time. And this compiler is always implemented in the Ngen.exe (Native Image Generator).
Normal JIT Compiler: The source code methods that are required at run-time are compiled into machine code the first time they are called by the Normal JIT Compiler. After that, they are stored in the cache and used whenever they are called again.
Econo JIT Compiler: The source code methods that are required at run-time are compiled into machine code by the Econo JIT Compiler. After these methods are not required anymore, they are removed.
5 - What's the difference between RyuJIT and Roslyn?
- Roslyn is the compiler that compile your code (C#, F# or VB) to IL.
- RyuJIT is a Just In Time compiler that compiles IL to a native code.
6 - What's the difference between .NET Core, .NET Framework, and Mono?
.NET Framework is the traditional world of .NET that only runs with Windows.
.NET Core is a free, cross platform (Linux, Mac, Windows) version of .NET for building many types of applications (websites, services, console apps and IOT).
Mono is an open source, cross platform version of the .NET Framework. Before .NET Core, it was the only stable solution to run .NET applications outside Windows. Currently, Xamarin and Unity runs on top of Mono.
7 - How GC works in .NET ?
.NET garbage collector is responsible to manage the allocation and release of memory for your application. Each time you create a new object, the CLR allocates memory for the object from the managed heap. However, after all the actions related to the object are completed in the program, the memory space allocated to it is a waste as it cannot be used. In this case, garbage collection is very useful as it automatically releases the memory space after it is no longer required.
There are 3 different phases in GC:
- Marking Phase: Creates a list of all the live objects. This is done by following the references from all the root objects. All of the objects that are not on the list of live objects are potentially deleted from the heap memory.
- Relocating Phase: The references of all the objects that were on the list of all the live objects are updated in the relocating phase. So the current living objects are moving to the next generation. There are 3 different generations in the .NET GC.
- Compacting Phase: The heap gets compacted in the compacting phase as the space occupied by the dead objects is released and the live objects remaining are moved.