Record the details of learning C # programming.
1. Value assignment expression:
int b=(i=1);Console.WriteLine("{0}",i=1);Console.WriteLine("{b}",b);
The value assignment expression in C # also has a value, that is, the value of the variable after the value assignment.
2. String Escape Character Processing:
string str="hello C#";string str="\"hello\" C#";string str="hello\n C#";string str="\\hello \\C#";string str=@"\hello \C#";
Note: Code results
Hello C #
"Hello" C #
Hello
C #
\ Hello \ C #
5. \ hello \ C #
Normal output of the first line
Double quotation marks are output in the second string, which are escaped using a backslash.
To wrap a line in the string of the third line, use the backslash plus n to wrap the line.
To output the backslash in the string of the fourth line, use two backslash
The fifth character is added to the front of the string with @ conformances. The backslash in the string is not properly escaped and can be output normally.
3. display the output information in the Console Program
Console.WriteLine("Somethings...");Console.ReadKey();
When you execute Console. ReadKey ();, the Console reads the input from the keyboard, and the Console displays the output information.
4. {} and;
// Block-1 ======================================== int age = 10; if (age> 20); {Console. writeLine ("adult ");} // Block-2 ========================================== int age = 22; if (age> 20) Console. writeLine ("adult"); Console. writeLine ("congratulations "); // Block-3 ========================================== int age = 22; if (age> 20) {Console. writeLine ("adult"); Console. writeLine ("congratulations ");}
Execution result of the above code block:
Block-1: Adult
Regardless of the value of age, the output result is the same, because the if statement is followed by a ";".
Block-2: Adult
Congratulations!
Regardless of the value of age, "congratulations" is output, because only Console. WriteLine ("adult") is used. The statement is within the if control range.
Block-3: Adult
Congratulations!
The preceding result can be output only when the age value is greater than 20.
Summary:
The semicolon (;) is the end mark of a statement and must be strictly used;
"{}" Is a control block and contains multiple statements for the condition judgment statement.
5. if... else nesting
Multi-level nesting can cause the code to fall into deep judgment and is not easy to read. level-1 judgment can increase the same level of judgment statements, increase the amount of code, and increase the number of judgments.
If .. else nesting, the two and three layers can be stopped, and the judgment condition relationship can be reasonably divided to reduce the nesting level.
6. Array
Int [] array = {1, 2, 3}; int [] array = new int [3]; // The number of array elements must be consistent with the declaration number. int [] array = new int [3, 3} // The following method is incorrect int [] array = new int [5] {, 3} // The array can save multiple words, almost any type can be declared as an array class Obj {} Obj [] objArray = new Obj [2]; bool [] boArray = new bool [3];
Array Index subscript) is from 0.
7. write comments
Write a comment. Both comments and meaningful comments must be written on the code.
What are the functions and functions of the class;
What is the method used and what functions are implemented;
What is a variable used;
The code is particularly error-prone and difficult to understand.
The easy mistake is the code description written in comments or the implementation process.
8. switch... case statement
int value=3;switch(vale){ case 2: Console.WriteLine("Haa2"+value); break; case 3: Console.WriteLine("Haa3"+value); break; case 6: Console.WriteLine("Haa6"+value); break; default: Console.WriteLine("Meile"); break;}
The switch... case statement is mainly used to deal with discrete value judgment.
650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/20344S554-0.gif "/> after the case statement in C # is executed, it is required to add break;
The following are special cases:
int value=3;switch(vale){ case 2: Console.WriteLine("Haa2"+value); break; case 3: case 6: Console.WriteLine("Haa"+value); break; default: Console.WriteLine("Meile"); break;}
When the processing logic of case3 and case6 is the same, it can be combined with case.
650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/20344S554-0.gif "/> about default: Is the code logical block that is processed when discrete values do not match.
650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/20344S554-0.gif "/> case followed by a specific value, cannot write variables. The code below is incorrect.
case i+1: ..... break;
9. Microsoft Visual Studio
Visual Studio is a C # programming IDE, but it is not unique. Without IDE, C # programming can still be completed using notepad.
In VS, multiple projects can be created under a solution, including the console, WinForm, and Web projects. In a project, multiple types of files and resource files in development can be added.
For CosoleApplication startup, you need to set the startup item in the tools --> options. You can select the project selected for the solution as the current startup Item.
10. Name
C # supports Chinese naming, but it is not recommended or recommended.
You can use the camel and Pascal methods for naming.
Reference C # naming convention http://www.soaspx.com/dotnet/csharp/csharp_20121018_9704.html
650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/20344V322-3.gif "/> learn, learn, and think.
This article is from the "Ajax girl" blog!