Microsoft .Net Framework
The .NET Framework is a managed, type-safe environment for developing and executing applications. The .NET Framework manages all aspects of program execution, like, allocation of memory for the storage of data and instructions, granting and denying permissions to the application, managing execution of the application and reallocation of memory for resources that are not needed. The .NET Framework is designed for cross-language compatibility. Cross-language compatibility means, an application written in Visual Basic .NET may reference a DLL file written in C# (C-Sharp). A Visual Basic .NET class might be derived from a C# class or vice versa.
The .NET Framework consists of two main components:
Common Language Runtime (CLR)
Common Language Runtime (CLR)
The CLR is described as the “execution engine” of .NET. It provides the environment within which the programs run. It’s this CLR that manages the execution of programs and provides core services, such as code compilation, memory allocation, thread management, and garbage collection. Through the Common Type System (CTS), it enforces strict type safety, and it ensures that the code is executed in a safe environment by enforcing code access security. The software version of .NET is actually the CLR version.
Class library is the second major entity of the .NET Framework which is designed to integrate with the common language runtime. This library gives the program access to runtime environment. The class library consists of lots of prewritten code that all the applications created in VB .NET and Visual Studio .NET will use. The code for all the elements like forms, controls and the rest in VB .NET applications actually comes from the class library.
Fig: .Net Framework Architecture
MSIL (Microsoft Intermediate Language) Code
When we compile our .Net Program using any .Net compliant language (like C#, VB.Net, C++.Net) it does not get converted into the executable binary code but to an intermediate code, called MSIL or IL, understandable by CLR. MSIL is OS and hardware independent code. When the program needs to be executed, this MSIL, or intermediate code, is converted to binary executable code (native code). The presence of IL makes possible the Cross Language Relationship as all the .Net compliant languages produce similar, standard IL code.
Just In Time Compilers (JITers)
When our IL compiled code needs to be executed, CLR invokes the JIT compilers which compile the IL code to native executable code (.exe or .dll) that is designed for the specific machine and OS. JITers in many ways are different from traditional compilers as they compile the IL to native code only when desired; e.g., when a function is called, the IL of the function’s body is converted to native code just in time. So, the part of code that is not used by that particular run is never converted to native code. If some IL code is converted to native code, then the next time it’s needed, the CLR reuses the same (already compiled) copy without re-compiling. So, if a program runs for sometime (assuming that all or most of the functions get called), then it won’t have any just-in-time performance penalty. As JITers are aware of the specific processor and OS at runtime, they can optimize the code extremely efficiently resulting in very robust applications. Also, since a JIT compiler knows the exact current state of executable code, they can also optimize the code by in-lining small function calls (like replacing body of small function when its called in a loop, saving the function call time). Although Microsoft stated that C# and .Net are not competing with languages like C++ in efficiency and speed of execution, JITers can make your code even faster than C++ code in some cases when the program is run over an extended period of time (like web-servers).
Framework Class Library (FCL)
The .Net Framework provides a huge Framework (or Base) Class Library (FCL) for common, usual tasks. FCL contains thousands of classes to provide access to Windows API and common functions like String Manipulation, Common Data Structures, IO, Streams, Threads, Security, Network Programming, Windows Programming, Web Programming, Data Access, etc. It is simply the largest standard library ever shipped with any development environment or programming language. The best part of this library is they follow extremely efficient OO design (design patterns) making their access and use very simple and predictable. You can use the classes in FCL in your program just as you would use any other class. You can even apply inheritance and polymorphism to these classes.
Garbage Collector (GC)
CLR also contains the Garbage Collector (GC), which runs in a low-priority thread and checks for un-referenced, dynamically allocated memory space. If it finds some data that is no longer referenced by any variable/reference, it re-claims it and returns it to the OS so it can be used by other programs as needed. The presence of a standard Garbage Collector frees the programmer from keeping track of dangling data.