After the basic video, found that some of the most basic knowledge points also mastered enough, summarized as follows:
1) placeholder
1 string name = " Zhang San " 2 int age = 28 3 decimal salary = 7600.33m ; 4 int number = 1000 5 " My name is {0}, this year {2} years old, my salary is {1} yuan", name,age,salary,number);
-{0}, {1}, {2} is a placeholder, followed by the parameter substitution placeholder
-parameters that can have more than a placeholder, such as number
-placeholders can appear in a non-sequential order
2) escape characters in a string
When we need to enter special characters in a string, such as line breaks, half-width quotes, backspace
1 Console.WriteLine ("");
-The transfer character is a character that is made up of a \+ of a letter
-There are two meanings to precede the string with an @ symbol
- Escape character no longer escaped
- To make a string line wrap
- Use two double quotes to represent a double quote
3) Variable naming rules
-Camel First Letter lowercase, the remaining words capitalized in the first letter
-Pascal First letter capitalized, the remaining words capitalized in the first letter
4) Convert Usage
1 " - " ; 2 int isore = Convert.ToInt32 (Strcor);
All types can be turned into string
5) Else forever and the nearest if pairing
1 intAge = the;2 CharSex ='F';3 4 if(Age <Ten)5 if(Sex = ='F') 6Console.WriteLine ("A");7 Else8Console.WriteLine ("B");9Console.readkey ();
else is paired with the nearest if (sex = = ' f '), not with if (AGE<10).
6) Multiple Case statements
1 Switch(month)2 {3 Case 1:4 Case 3:5 Case 5:6Console.WriteLine (" Days");7 Break ;8 ......9}
7) Do While
1 string " y " ; 2 Do 3 {4 Console.WriteLine ("Again"); 5 while " N ");
8) When an exception occurs in try, the code following the try exception is no longer executed, immediately jumps into the catch execution
1 Try 2 {3 intScore =Convert.ToInt32 (Console.ReadLine ());4Console.WriteLine ("In try");5 }6 Catch7 {8Console.WriteLine ("In catch");9 }TenConsole.WriteLine (" Over");
9) Enumeration: Define a type and specify a value of this type when defining this type
1 enum MyType {value1, value2, Value3 ...}
-enumerations are defined at the same level as class definitions, so that classes can use enumerations under the same namespace
- enum types can be converted to int types
-Ensure data consistency
-No need to memorize data values
The role of the enumeration:
- Limit the assignment of the user, only select from the values enumerated
-No need to call memory value, just select value
1 enumGender2 {male,3 female4 }5 6 Gender sex;7Sex =Gender.male8 9 Switch(Sex)Ten { One CaseGender.male: AConsole.WriteLine ("male"); - Break ; - CaseGender.female: theConsole.WriteLine ("female"); - Break ; - } - + strings =console.readline (); - Try + { A sex = (Gender) (Enum.parse (typeof (Gender), s)); at } - Catch - { -Console.WriteLine ("the gender you entered is wrong"); -}
-male = 1
-female = 2 (default + 1)
-Conversion of strings and enumerations sex = (Gender) (Enum.parse (typeof (Gender), s));
C # Basic Knowledge Summary