001 "HelloWorld" parsing code block
//here is the comment below is the introduction of namespacesusingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;//define the namespace to end with ' {', to '} ',namespace_001_ Our first CSharp program//try not to use Chinese{ classProgram//Defining Classes { Static voidMain (string[] args)//defining the Main method{//here is the method bodyConsole.WriteLine ("Hello World");//first line of code } }}
002 "Pause"
Start with CTRL+F5 or add the following code (read input)
Console.readkey ();
003 "Output"
1. Basic output
System.Console.WriteLine ("Hello1");//The output comes with a newline character (the previous system represents the namespace, and if it is introduced, it can be used without adding)System.Console.WriteLine ("Hello2"); System.Console.WriteLine ("Hello3"); System.Console.Write ("Hello1");//No line break after outputSystem.Console.Write ("Hello2"); System.Console.Write ("Hello3");
2. Formatted output
// where {} becomes a tag, the following number takes the previous value, 0 represents the first, and so on // Note that undefined tags, such as {5}, cannot be used. No spaces within the tag, for example {0}, will error Console.WriteLine (" two numbers added {0}+{1}={2}"334 ( PNs); Console.WriteLine ("{0}*{1}={0}"51); // tags can be used multiple times
004 "Declaring variable type"
declaration Variable and C difference are not all, but more than repeat
< type >< variable name >;
for example int A;
type is similar to C, nothing more than int float double.
It is worth noting that the C # default floating-point double, to define float to use a = 12.5f. The value of the bool type is true and false instead of 0, 1.
The escape character is the same as C.
It is worth noting that the output does not recognize the escape character after the @
string " I am A good man.\nyou is a bad girl! " ; Console.WriteLine (str1); string @" I am A good man.\nyou is a bad girl! "" "; // End with two quotes to represent a quotation mark Console.WriteLine (STR2);
Use @ To define a string in multiple lines
string @" I am A good man.\nyou is a bad girl! "" " ; Console.WriteLine (str2);
Use @ To identify the path
string " C:\\xxx\\xx\\xxx.doc " ; Console.WriteLine (path); string @" C:\xxx\xx\xxx.doc "; // @ does not recognize the escape character, so it is convenient to identify the path Console.WriteLine (path2);
"C # Learning Path" 001. Basic operations