Written by Cash (Tianxia Seventh) 2002.04.07 Copyright, Records No Cashcao@msn.com
Agreement
// a typical HelloWorld program using C # written system; class helloworld {public static void main () {Console.Writeline ("Hello World!");}}
I forgot my first time I used C # to the world, but I can sure I have already greeted, and I use the beta1 version. Now you can go to http://msdn.microsoft.com/downloads/default.asp?url=/downloads/sample.asp?url=/msdn-files/027/000/976/msdncompositeDoc.xml to download .NET Framework The official version of Software Development Kit (SDK), including the previously mentioned .NET Framework, and writing, compiling, testing, development .NET Framework application needed - document, example, command line tool, and compiler . After installing, you can develop and run the C # program, but the general suggestion is: must see the documents and examples of the .NET Framework SDK, if you can write it again, then it is fine. When I first saw C # code, I also thought it was like Java, an image of an image is: C # and Java are a pair of twins, from the grammatical perspective, their common father is certainly non-C Mo Please note that not VC ). For a person who has learned a Java language (such as under the following), it is very easy to understand this code: the first line of course is a comment, C # supports two annotation methods, starting with "//" Note and multi-line comments used in "/ *", "* /". The second line is imported into the SYSTEM package (called name space in C #, namespace), allowing us to easily call all classes in the Microsoft.Net base library system, in this example The "console" class in the System name space is used to run the result in the console window output program. As mentioned earlier, the C # does not have a built-in input and output statement, all of which need to be implemented completely from the .NET base class library. The role of this sentence is to tell the compiler to find the Console class for call. Next, a class HelloWorld is declared. There is a special method main () in this class. Each executable file needs to have an entry point. In C #, this entry point is the main () method, this method will be in the program. Call it when startup. In this method, console is a class under the namespace SYSTEM, which represents the console. This is called a static method WRITELINE (). Like C , static methods allow us to act directly on classes rather than instance objects. The WriteLine () function accepts the parameter "Hello World!" Of the string type and feed it into the console display. As mentioned earlier, C # does not have its own class library, it acquires the Microsoft.net system class library. Here is the console output operation we want by getting system.console.writeline () in the Microsoft .NET system class library. Now use the notepad to write this code and save its file name as HelloWorld.cs, where ".cs" is the extension of the C # source code file. Then type "CSC HelloWorld.cs" compile file in the command line environment that configures the C # compiler. You can see the compilation output file helloWorld.exe. Type HelloWorld to execute this file to get the following output: Hello World!
This is the first C # program, we use csc.exe to compile it, for this C # compiler, as described below: 1. It is released free of charge with .NET Framework SDK, you can call 2 on the DOS command line 2. Its usage is as follows: CSC SourceFile.cs /out :targetfile.exe If the target file name is specified without using the output parameter, the default output is the source file name 3. In general, it is under the system folder (Windows or WinNT) The Microsoft.Net/framework/v1.0.3705 folder 4. If you install vs.net, you can activate the Visual Studio.Net Command Prompt window from the Visual Studio.Net Tools project group. This is a configuration C # compiler. Command line environment 5. Compiled C # programs after using CSC.exe is not machine code (despite it. EXE's suffix name). As mentioned earlier, the C # program is only compiled into a MSIL code.
The C # compiler (CSC.exe) compiled file is not a strict executable file (does not contain machine code), but a file in a PE (Portable Executable) format, although it also owns .exe's suffix name. In this PE file, it is not only included in the intermediate language, but also contains metadata and a standard executable file header of the target platform added by the compiler. In the middle language, it is precisely that Microsoft Intermediate Language (MSIL) is a language defined by Microsoft, which is bound to source code and machine code. In the CLR, it first is packaged into the pseudo code (P code) of the EXE format by a particular language compiler. Then convert it to a local code execution by a particular compiler. For Microsoft Intermediate languages, an image of an image is that if the CLR is an operating system, then the Microsoft intermediate language is the ASM assembly language on the .NET platform. It is more advanced than most CPU machine languages, such as it understands the object type, and has creation and initializing objects, calling on the object's virtual method and direct operation of processing array elements. It also has instructions that have discovered and captured an abnormal condition for error handling. Metadata and MSIL together exist among the compiled program files, describe the definitions of the type included in this program, various types of signatures, and other data, which are equivalent to the previous type library, while Other external classes cited by this procedure are also described. The main role of metadata is to provide more information related to the code to the CLR. Basically, metadata is used for the following tasks: used to represent the information of the CLR application, such as positioning and loading classes, instances of these classes in memory, resolving the call, translation IL is the original code, strengthen security and set the run-up context boundary . A process that is written in the C # language written in the CLR environment is this: first compiled by the C # compiler into a PE file containing intermediate language and metadata, when we call this file in the system, CLR will Start a compiler to convert the MSIL code contained in this PE file into a managed local code. This compiler for converting MSIL code is a Just In Time, JITER. Please note that it is not a C # compiler we used in front. Now let's take a look at how the JIT compiler works: When the PE file is called, the Jie compiler breaks down into MSIL and metadata. At this time, MSIL does not directly let the .net to call the local system interface, but Specify the .NET system to compile those CLR DLLs needed, compile 100% of the local code. The entire process is as follows: When a type is loaded, the loader creates a stub and enables it to each method of the type. When a method is called for the first time, the stub gives the control over the JITER. JITER compiles MSIL to a local code and points the stub pointer to buffer local code. Methods that have been compiled by Jiter then directly call the generated local code, reducing JITER compiling and executes code. It can be seen that Jicter does not compile all MSIL to a local code in one time, but it is time to compile when we need, that is, some code may never be compiled. It is clear that the benefits of doing this are both guaranteed the safety of the runtime and will not lose too much efficiency. This is the step of execution of a C # program. The whole process is this: 1) Compile source code as intermediate language 2) Mounting host code, including Laying Out classes, and creates JIT compilation .
By performing a regular verification, including strengthening some access rules, the type loader also enhances security 3) Convert IL into raw code 4 with JITER 5) Mount metadata, check the type of security and method 5) Garbage Collection (GC) and Abnormal Process 6) Depicting and Finding Define Services 7) Managing Threads and Contexts and Remote Management. Don't have to understand these concepts, you will experience them in the future, you will do the wonderful, now you need to do it (if you haven't done it yet), you find Ildasm.exe this file (in general, It will be in the same folder with csc.exe). As the name suggests, this is an MSIL's disassembler (.NET Framework IL Disassembler), enter ildasm helloworld.exe /out=helloworld.IL under the command line window. You will get two files: helloworld.il and helloworld.res. The former includes anti-compiled metadata and MSIL code, which is the extracted resource file. Use Notepad to open the helloworld.il file, you can see it define and implement a HelloWorld class inherited from System.object and two functions: main () and .ctor (). Where .ctor () is the constructor of the HelloWorld class. In this file, it also includes metadata and other relevant information. If you think this is not intuitive, you can type iLDASM HelloWorld.exe on the command line window so that you can start the ILDASM window and show us the anti-compiled HelloWorld.exe file. Please read these code a few times, now understand that all of these content is not important, but I hope you can also see the metadata in the file, which contains all Runtime and compilers need for assemblies and their modules, types. And members (such as methods). I want to talk about learning. As you know, in our environment, learning always means a painful process, learning a new knowledge seems to always think about something, I don't think there is anything wrong, but I always I feel that in addition to getting a high salary and respected, learning should also bring us more happiness. Some knowledge We may not use it now, such as some of the content mentioned earlier, but we understand, it is a happy thing.
Wisdom itself is good. One day we will die, and the road to pursue wisdom will be walking. I can't see it after the death. But when I was alive, I thought about this, I was happy. Wang Xiaobo
Today is April 7, 2002. It is a jealous day of Wang Xiaobo for three days. I don't know how many people will remember this day. I will remember this person. At the end of this article, I recommend the Wavelet Works - Every mental mature person should read the text of Wavelet. In his scribble, there was a saying that he said in a person as a programmer: "Tonight does not stop this C , Laozi is not sleeping!"
>>> Not finished, to be renewed ...