Chapter 1 C # development environment
C # The simplest editor can use notepad, but I don't recommend using it to edit the source code. The reason is that if you deal with the real programming language, use the NotePad editing the source code to compile the source code, but you still don't know where it is. You have several options: First, configure Visual C 6.0 in Visual Studio 6 to make it work with the C # source file. Second, select Microsoft's latest Visual Studio 7, its IDE style is very cool, there is also VFP, C , VB, C # in the same environment, but very resource, so use it to consider clear. Let's introduce the installation of Visual Studio 7:
The choice of operating system is best to choose WIN2000 Chinese version (English version can also, of course, using Chinese version), upgrade to SP1 after installation (ServicePack 1, Chinese version of the Chinese version of Win2KSP1), then install IE5.5. Install Q274294_W2K_SP2_X86_CN.EXE patch, so far, basic requirements have been reached. Start installing vs.net, extract the downloaded files or copy the No. 1, No. 2 disc to a new directory of a hard disk (about 850M space), then enter the directory, run the setup file. If you are installed in the Chinese version of Win2000, you need to enter the setup directory and then run the SETUP program inside. The installer prompts you to install some components that do not meet the version, including FrontPage Server Extension QFE, IE5.5, please specify the directory location of the upgrade component or 3 CD. After upgrading, the system is installed as XML3 and other components. After upgrading the component, you will start installing the VS.NET. Time is about 35 minutes (time according to your machine configuration) The above installation process, if necessary, you must restart your computer, mention it above, most can go to Microsoft's website (http://www.microsoft.com) download. In fact, as long as you install the NGWS.NET SDK, you can directly compile the C # program. When installing the NGWS SDK, the installer automatically adds the path where you join the C # compiler in the environment variable Path. So you can write a C # program with any editor, the suffix is stored as .cs, then perform CSC xxx.cs in the command line to generate the EXE file. Third, you can use any third-party program editor, it is best to support the number of rows, color coding, tool integration, and good search feature, I recommend one (Sharp Develop, a developing tool dedicated to C #). The IDE interface is as follows: Now "Hello World" takes the easiest "Hello World" program for the development environment of the C # as an example, as follows:
1: Class HelloWorld2: {3: Public Static Void Main () 4: {5: System.Console.writeline ("Hello World"); 6:} 7:} In C #, code block (statement group) is made of large arc ({And}) hosted. So, even if you have no experience in C before, you can also say that the main () method is part of the HelloWorld class statement because classes are enclosed in the defined bunary arc. The entry point of the C # application is the Static Main method. This is a bit like C / C , but the case is different, it must be included in a class. There is only one class to use this flag definition unless you tell which main method it should use, no side, a compilation error will occur. Compared with C , the first letter of Main is uppercase M instead of lowercase letters you have used. In this method, your program starts and ends. Other methods can be called in the method - as in this example, used to output text - or create objects and activate the method. As you can see, the main method returns a void type. Public Static Void Main () Although see these statements, C / C programmers will definitely feel like they have met, but other programmers are not the case. First, public access flag tells us that this method can be accessed by any program, which is the necessary condition it is called. Second, Static means that there is no instance of creating classes first, you can call the method - what you have to do is calling the method using the class name. HelloWorld.main (); another important aspect is the return type. For method main, you can select Void (meaning that there is no return value at all), or use int as an integer result (an error level returned by the application). Therefore, two possible main methods are: public static void main () public static int main () C / C programmer will also know the back I will mention - the array of command line parameters that can be transmitted to the application. Such as: public static void main (string [] args I don't want to explain how to access the parameters in detail, but I want to give a C programmer a warning: and C , the application path is not part of this array. Just those parameters are included in this array. After the MAIN method is not brief introduction, let us focus on the only real code row - this line code displays "Hello Wold" on the screen. System.console.Writeline ("Hello World"); if you don't have SYSTEM, everyone will guess WriteLine is a static method of console objects. So what is SYSTEM? It is a namespace containing the console object (range), in fact, not every time the console object is prefixed before the name space, you can like the appraisal shown in Listing 3.2, in the application Introduce namespace. Introduce namespaces in the application, the code is as follows: