Figure 1 shows traditional compilation in which we compile the source code and then the compiler produces executable binary format file.
In .NET the source code is converted into native code or machine code in two phases.
Phase 1: The compiler of any .NET language converts the source code into Microsoft Intermediate langunage (MSIL) commonly known as IL (Intermediate Language) or Byte Code.
Phase 2: The CLR (Common Language Run Time Environment) converts this byte code which is a assembly file into machine code. (Read the detail of these two phases in later section).
Figure 2
Figure 2 is a diagram of the compilation process in .NET.
".NET supports multiple programming languages i.e C#,C++,VB etc. When you compile a program in .NET environment ,the compiler of corresponding language converts the source code into byte code or IL ,which is a assembly file. Then the CLR (Common Language Runtime) converts this byte code into machine code or native ."
Why bother having extra step of converting source code into machine code
The key reasons are portability between operating systems, interoperability between languages and execution-management features such as memory management and security.
If the .NET Framework exists for a platform, that platform can run any .NET program. The ability of a program to run without modification across multiple platforms is known as platform independence. Code written once and run everywhere without modification saves our time and money.
(See the Interoperability feature of .Net in later section).
What is CLR
- CLR not just convert MSIL into machine code, rather it manages memory, security and other features reliving the programmers from these responsibilities. Like in C++, you have to manage memory by your own, this lead to complexity and you need extra capabilities for that.
- CLR holds information about the storage of data types and objects.
language Interoperability
.NET provides high level of language interoperability. The programs written in different languages are all compiled into byte code and then these different parts are combined to create a single application. For example, in a software one module of the software is written in C# and other module is written in VB but when they are combined they act as a single application. This feature of .NET distinguish it from other development environments.
Any language that can be compiled into byte code or IL is called .NET-compliant language.
Language interoperability offers many benefits, for example, C#, Visual Basic .NET and Visual C++ .NET developers, for example, can work side-by-side on the same project without having to learn another programming language—all their code compiles into MSIL and links together to form one program. In addition, the .NET Framework can package old and new components to work together. This allows companies to reuse the code.
Here is a list of some .NET-compliant language.
- APL Oberon
- C# Oz
- COBOL Pascal
- Component Pascal Perl
- Curriculum Python
- Eiffel RPG
- Fortran Scheme
- Haskell Smalltalk
- Java Standard ML
- JScript Visual Basic .NET
- Mercury Visual C++ .NET
- F#
- IRON PYTHON
- IRON RUBY
- A#
- J#
- NETCOBOL
- P#