Guys, I've been working in a project and one of my teacher wants me to explain how .net Framework works.
I wrote that we can use .net framework code to use it in other languages and I need to 开发者_JS百科explain why. Can you help me?
.NET languages (C#, VB.net, many others) compile to .NET bytecode, which is then interpreted by Common language runtime (CLR), which is a virtual machine. That's the short answer.
There is a nice image on Wikipedia article about CLR that illustrates how source code gets transformed to native code.
.NET bytecode contains information about classes, methods, and other info that can be used by other languages that are based on .NET.
A useful utility to test this is the .NET reflector, which can be used to reverse engineer .NET bytecode and turn it into C# or Visual Basic code.
For more details, search the net for CLR and you'll find plenty of resources.
The output of any compiler whether it is a C# compiler, VB, or Delphi is created in the same intermediate language (IL) AKA bytecode. Because of this the outputs of any of them can be combined (linked) together for execution. This also allows running this code on any processor which has the JIT compiler available (JIT - just in time compilation of bytecode in IL into the hardware specific one for a given processor architecture)
Compiling/interpreting code is about transforming the code, usually from a human readable form to a more efficient form that's closer the language of the processor.
Microsoft made a virtual machine called the Common Language Runtime. You could think of the CLR as a more flexible processor created as software. The CLR also introduces constraints that help ensure comparability with Microsoft's operating systems.
Any programming language designed to compile to bytecode that the CLR understands can be used as a .NET language. The CLR doesn't care how the bytecode came to be, so you could even make your own language to produce bytecode.
I need to explain why
The simple explanation is because regardless of the coding language, it compiles down to .net pseudocode that can be executed by the framework. Regardless of the original coding language the compiled pseudocode looks to same for the same operation.
This is over-simplified of course but it's a starting point and you can do some quick research to fill in the details.
精彩评论