1 Introduction
C # Is a concise, fashionable (?), Object oriented (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 and
The power of C ++.
C # Will be part of vs7. Vs7 also supports vb, vc, and markup language-VBScript and JScript. All these languages
Will be supported in Next Generation Windows Services (NWGS) platform (c # requires
The nwgs sdk package can be downloaded from the website of m $ ). With this stuff (NWGS), c # does not need its own class library,
Use mature libraries such as vc and 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 --
You can leave the whole banana to me .) Then, the nwgs sdk is required! (82.4 mb, not big. Hey, good news
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
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
It must be unique within the scope of 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. Moreover, beginners
Don't know! I recently learned that there is another namespace and using. :)
It is really useful in {namespace-body}, including the description of "Console. WriteLine" on the fifth line
Definition (will be mentioned later ). System is defined by NWGS. We only need to use it. For
What file is defined, so 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 ++ can be said to be a step closer, avoiding a lot of annoying details. If you have never learned c/c ++,
Ignore this. Namespace will be discussed later.
2: class idontlikeHelloworld
Class: Another keyword "class" in the c language ". Represents a series of features (official saying: attributes) and behavior methods, including
With it, your program can be "alternative" to create something different from what you have! Here, I have defined
"IdontlikeHelloworld ". Note: This is also mandatory for c #. It is required for every executable program. What do you want
You can record a pair of curly braces following the class you define. Note: "{" and "}" correspond one by one,
"(" And ")" are the same.
4: static void Main (){
Main () is the first action (behavior method) in this example. It belongs to the idontlikeHelloworld defined by Alibaba.
Class method. And c # is mandatory. It is the real start of the program! The order of statements followed by "{}" is the program
Running order! 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 System
A class of namespace. 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" Search "Console. WriteLine" in "ngws sdk consumer entaion" And remember to check
"Search for titles only", which lists 19 items. Okay, it's done! In fact, there is still "." Not said! Haha... lei si la !!!!
(Before resuming)
"." Is called a separator (separator), used to connect the name. As shown in the "Console. WriteLine" above, the class and its
Method connection. In this way, we can use the ready-made method set. Here I will review my examples and look at namespace and
"." Is used together, and why is the keyword namespace used. Change the example slightly :*/
/* IdontlikeHelloworld. cs */
1: // using System;
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 be changed
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 the introduction of "class" to c ++
It is not a function to extend the "struct" keyword. For example, "=" is only used for value assignment, and "=" is only used to judge equality. This is c/c ++ and c #
An important feature in syntax. 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,
It eliminates the barriers between programming languages and facilitates the use of libraries written in other languages. For example, the "Console" class can be written in c # or any other language.