(Post)
The key is to understand CLR (runtime in public languages)
. Net Framework is composed of two independent and related parts: Clr and class library. CLR is the service it provides for us. Class Library is the function it implements .. most of net's features-garbage collection, version control, thread management, and so on, all use the services provided by CLR.
When you are. when the Net Framework compiles the source code, the target code is not a machine instruction that the CPU can recognize, but a kind of code called "Microsoft intermediate language (msil, or IL for short). CLR provides a real-time compiler for compiling il code into local machine code. in this way, the CLR can make the code portable, because. NET application source code must be compiled into il code, which can run on any platform that provides CLR services. from the perspective of CLR, all languages are equal, as long as there is a compiler that can generate il code, which ensures the interoperability of various languages.
The code for writing and using the CLR service for CLR is called "managed code", and the code that does not use the CLR Service (that is, the code you have been writing for many years) it is called "unmanaged code ".
Discussed in C ++ in.. Net hosting environment, because C ++ is not. therefore, Microsoft needs to expand C ++ to introduce the concept of "managed extension, it allows us to use it in C ++ projects.. NET Framework. If you have the following development needs, you must use managed extensions:
1. Porting existing C ++ code to the hosting environment
2. Access the. NET Framework class in C ++ code
3. Access the existing C ++ code through the. NET language