Translate to c # language reference microsoft press!
/* 1 Introduction
C # Is a concise, fashionable (?), Object oriented is a type-safe programming language. It (pronunciation: C sharp) is developed from c/c ++ (? I think it is more like java), and c/c ++ is a language. Therefore, it is easily accepted by c/c ++ programmers. The goal of c # is to combine the high yield of Visual Basic with the simple power of C ++.
C # Will be part of vs7. Vs7 also supports vb, vc, and markup language-VBScript and JScript. All these languages are supported in the Next Generation Windows Services (NWGS) platform (c # requires an nwgs sdk package, which can be downloaded on the m $ website ). With this stuff (NWGS), c # does not need its own class libraries, but uses mature libraries such as vc or vb. C # does not have its own class library.
All nonsense.
1. 1. An example of old soil (can't I change it ?) */
/* IdontlikeHelloworld. cs: such a out sample :(*/
1: using System;
2: class idontlikeHelloworld
3 :{
4: static void Main (){
5: Console. WriteLine ("I dont like Hello world ");
6: Console. ReadLine ();
7 :}
8 :}
/* If I want to publish a book, I will consider a better example. ^ & ^
Let's talk about how to run it first. First, you need windows2000! (Yes, It is it. Please do not drop the peel anywhere-the whole banana can be thrown to me .) Then, the nwgs sdk is required! (82.4 mb, not big. Hey, fortunately, it does not have its own class library .) After installation, enter the following in the directory where your program is located:
Csc idontlikeHelloworld. cs (add a enter key)
Is it a little retro? This operation will generate
The idontlikeHelloworld.exe file. Double-click it. You can see that:
I dont like Hello world
Press enter to end it, which is very simple.
However, it is better to save it as a file suffixed with. c.
(That is, idontlikeHelloworld. c ). In this way, you can use the vc IDE for typing and editing. Vc
Txt editor is the best (vc, NO !!!). Then:
Csc idontlikeHelloworld. c (add a enter key)
The final results are exactly the same.
Well, now the analysis Syntax: (c # There is nothing new in syntax:-|)
1: using System;
Using is actually a keyword of c ++, and its meaning in c # is similar (that is to say, I am not sure about 100%, sorry ). Using is used after another keyword namespace. Let's take a look at namespace first.
Syntax (syntax) :( from MSDN)
Namespace [identifier] {namespace-body}
My understanding:
Identifier: Here it is System (remember: c # is the same as c/c ++, It is case sensitive !). System must be unique within the scope of its use. That is, there cannot be a second System, but there can be a system. I don't want to elaborate on the scope of "it". It is only possible to grasp it in practice. In addition, beginners do not have to know! I recently learned that there is another namespace and using. :)
It is really useful in {namespace-body}, including the "nsole. WriteLine" declaration and definition of the fifth line (which will be mentioned later ). System is defined by NWGS. We only need to use it. As for what file the System is defined in, you don't have to worry about it! Submit it to the Editor (just the one who got it) to find it. This replaces the "# include" in c/c ++. It can be said that it is a step closer to avoid a lot of annoying details. If you have never learned c/c ++, ignore it. Namespace will be discussed later.
2: class idontlikeHelloworld
Class: Another keyword "class" in the c language ". It represents a series of features (official saying: attributes) and behavior methods. With it, your program can be "alternative" to create something different from what you have! Here, I define "idontlikeHelloworld ". Note: This is also mandatory for c #. It is required for every executable program. What you want to do is to record a pair of curly braces following the class you define. Note: "{" and "}" correspond one by one, and "(" and ")" are the same.
4: static void Main (){
Main () is the first action (behavior method) in this example. It is a method of the idontlikeHelloworld class defined by Alibaba. And c # is mandatory. It is the real start of the program! The order of statements followed by "{}" is the running order of the program! In this example, there is only one row (why is the sixth row used? You can get rid of and compile it again) to output a sentence.
5: Console. WriteLine ("I dont like Hello world ");
Very strange. The Console (remind me again: note the case sensitivity) is not defined by me. Where does it come from? It actually belongs to a class of Systemnamespace. WriteLine () is a method in the Console class used to display a sentence (string ).
Here we only use 1/18 of this method! And is one of the simplest! Others have the opportunity to talk about it again. You can also use
"Console. WriteLine" searches for "Console. WriteLine" in "ngws sdk example entaion". Remember to check "search only title", which lists 19 items. Okay, it's done! In fact, there is still "." Not said! Haha... lei si la !!!!
The statement is not fluent, And I will improve it later (update). Please forgive me! -- "Please use a fork for soup"
"." Is called a separator (separator) to connect the class to its method, as shown in "Console. WriteLine" above. In this way, we can use the ready-made method set. Here, I will review my example to see how namespace and "." are used together, and why the keyword namespace is used. Change the example slightly:
/* IdontlikeHelloworld. cs */
1:File: // usingSystem;
2: class idontlikeHelloworld
3 :{
4: static void Main (){
5: System. Console. WriteLine ("I dont like Hello world ");
6: System. Console. ReadLine ();
7 :}
8 :}
/* When I unregister "using System;", I add "System" to the fifth and sixth rows ". The program results will not change. However, it is obvious that this is cool, so "namespace" is introduced ". In fact, the class should be able to accomplish the same function.
However, designers may not want a keyword to cover too many features. I remember that when c evolved to c ++, it introduced "class" instead of extending the "struct" keyword function. For example, "=" is only used for value assignment, "=" is only used to judge equality. This is an important feature in the syntax of c/c ++ and c. This design has many benefits. Have the opportunity to chat again.
If you have never learned c/c ++, skip the following content. C # syntax is different from c/c ++, for example:
1. C # There is no ":"; "->" only in small pieces of the program. "." Should be used in c #.
2. C # You do not need to declare the definition before using it. Same as java.
3. C # canceled the use of "# include" to import other program text files, and the use of symbolic handles to introduce others' code. In this way, the obstacles between programming languages are eliminated and libraries written in other languages are easily used. For example, the "Console" class can be written in c # or any other language.