top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

What are the advantages of Common Language Runtime (CLR) in .NET?

0 votes
3,389 views
What are the advantages of Common Language Runtime (CLR) in .NET?
posted Mar 21, 2017 by Rohini Agarwal

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

2 Answers

0 votes

CLR is Common Language Runtime which is the heart of .NET Framework. In an application which is without CLR, when the application is compiled, it produces the machine language which the Operating System can understand. Hence the source code is directly converted into machine code.

But the problem with this approach is that if you try to run the same application in some other operating system say Linux/Unix, the application will fail to run.

Hence to resolve this .NET has CLR . The CLR contains a JIT compiler. At first the source code is compiled to an intermediate language known as MSIL.This intermediate language is then compiled to the machine code by the JIT compiler.

Hence whether it can be VB.NET/C# or any other .NET compliant language all the source code is not directly converted to native code but it is converted to intermediate code and later by JIT to machine code.

The main advantages of CLR are:
1. It provides flexibility of application to run in different operating system.
2. Garbage collection(Memory allocation and deallocation)
3. Code access security i.e restriction of unauthorized access to the code.
4. Code verification.

answer Mar 21, 2017 by Shweta Singh
0 votes

The Common Language Runtime (CLR) Environment provides a rich set of features for cross-language development and deployment. CLR supports both object-oriented languages and procedural languages. CLR manages the execution of code and provides various services such as security, garbage collection, cross-language exception handling, cross-language inheritance, support for the Base Class Library (BCL), and so on. These are the main constituents of the CLR:

The Common Language Runtime helps you to compile your program code in to an intermediate language called the Microsoft Intermediate Language (MSIL). During runtime this MSIL is converted to the native code and executed. The advantage of the CLR is to compile the code into MSIL which has lots of benefits.

Since all the code is compiled to an MSIL, it is possible to write the code in any language thus giving you the independence to write in any language. MSIL is part of the Portable Executable (PE) file that is created and the other part of the PE contains metadata. This metadata is used to load the classes and it also helps you to load the assemblies dynamically when needed.

The other benefit of using CLR is to enforce security and you can set context boundaries during runtime. Memory handling is done by the CLR which frees the developer from worrying about allocating and de-allocating memory within their program. The lifetime of the objects in the memory are handled through a process called Garbage collection which is unique to the CLR.

answer May 27, 2019 by Rushabh Verma R.
...