C #,. NET Framework, CLR relationships

Source: Internet
Author: User

Many people do not differentiate between the three C #,. NET Framework (. NET Framework), CLR (Common Language Runtime, Common language runtime), and assume that its version number is one by one. Not actually,. NET Framework is a standalone package that contains tools such as the CLR, the class library, and the associated language editor. C # code is compiled and then run in the CLR environment. Because. NET Framework 3.0/3.5 is actually. NET2.0 extensions (just add some new assemblies), so. The CLR version of net3.0/3.5 is still 2.0. and. NET3.0 actually extends only the WF, WPF, WCF, WCS, and other components, and does not provide a new C # compiler until. The compiler for c#3.0 was packaged in NET3.5. NET4.0 has added some new features to WF and WCF on 3.0, so. The corresponding relationship between the versions of the NET Framework, the CLR, and C # is shown in the following table:

That is, for c#3.0 new features that do not involve new assemblies (such as automatic attributes, anonymous attributes, and so on). NET2.0 can also be run in an environment where the CLR is unaware of these features.

1, C # is an object-oriented programming language, is for development. NET Framework of the program.

(1) C # is derived from C and C + +, so it can invoke native native functions written by C/s + + without loss of the original powerful functionality of C/s.

(2) The program source code developed by C # is not compiled into binary native code that can be executed directly on the operating system. It is compiled into an intermediate code and then passed. NET Framework of virtual machines (that is, the CLR) to execute. So if the computer is not installed. NET Framework, then the program will not be able to be executed. In the course of execution,. The NET Framework translates the intermediate code into a binary machine code, which makes it run correctly. The binary code of the final translation will be stored in a buffer. So once the program uses the same code, the version in the buffer will be called. So if one. NET program is run for the second time, the translation does not need to be performed a second time, and the speed will be significantly accelerated.

2,. NET Framework consists of three parts (for example):

1) Introduction to the CLR reference 3

2) Programming Tool: Covers everything needed for coding and debugging: Includes: VisualStudio integrated development Environment,. NET-compatible compilers (for example: C #, VB, JScript, and managed C + +), debuggers, server-side improvements (such as ASP.

3) BCL (base Class Library): Yes. NET Framework, and it can also be used in your program. Some of the following classes are included.

1> Common base classes: These classes provide a very powerful set of tools that can be applied with a wide range of programming tasks, such as string manipulation, security, and encryption.

2> Collection classes: These classes implement lists, dictionaries, hash lists, and bit arrays.

3> Threads and Synchronization classes: These classes are used to create multithreaded programs.

The 4>xml class, which is used to create, read, and manipulate XML documents.

3. The CLR (Common language runtime) executes the run-time hypervisor: Includes memory management, code security validation, code execution, and garbage collection. Such as

(1) Automatic garbage collection: The CLR has a service called GC (Garbage Collector, garbage collection), which automatically manages memory for you.

1) GC automatically removes objects from memory that the program no longer accesses

2) GC is a programmer who no longer cares about many tasks that must be performed before, such as freeing up memory and checking for memory leaks. This is not a small feature, because checking for memory leaks can be difficult and time-consuming.

4, the code compilation process:

(1) The compiler compiled into the Cil:.net language accepts the source code file and generates an output file called an assembly. The assembly can be an executable file or DLL (as shown)

The code in the 1> assembly is not native code, but is an intermediate code called CIL (Common Intermediate Language, Common Intermediate language).

The 2> assembly contains information that contains the following items: CIL of the program, metadata for the type used in the program, metadata for other assembly references

(2) Compile the cost machine code and execute it: The CIL of the program is not compiled until it is called to run the cost machine code. At run time, the CLR performs the following steps (for example)

1> checking the security characteristics of an assembly

2> allocating space in memory

3> sends the executable code in the assembly to the real-time (just-in-time) compiler, which compiles a portion of the cost machine code.

The executable code in the assembly is compiled by the real-time compiler when needed, and then it is cached for execution in later programs, which means that the code that is not called is not compiled with the cost machine code, and the code that is called is compiled only once.

Once CIL is compiled with the cost machine code, the CLR manages it as it runs, performing tasks such as freeing up non-primary memory, checking array boundaries, checking parameter types, and managing exceptions. There are two important terms that are generated here:

Managed code: for. NET Framework is called managed code and requires the CLR.

Unmanaged code: Code that is not running under CLR control, such as the win32c/c++ DLL, becomes unmanaged code.

(3) Compilation and execution Overview: Regardless of the original source file language, understand the same compilation and execution process.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.