C # basic notes (Day 4 ),
1. Exception capture trt-catch
① Various exceptions often occur in the program. If you want the program to be stronger, you should often use try-catch to catch exceptions in the code.
② No other code exists between try-catch.
③ If the program in try is not abnormal, the code in catch will not be executed. If an exception occurs in the program in try, even if there are still 100 lines of code after this line of code, the code will be skipped to catch.
2. Scope of Variables
① The scope of the variable is the range in which you can use the variable.
② The scope of a variable generally starts from the angle brackets closest to it and ends with the ending angle brackets corresponding to the angle brackets.
③ Within this range, we can access and use variables. If the range is exceeded, the access fails.
3. switch-case
It is used to process multi-condition value judgment.
Syntax:
Switch (variable or expression value)
{
Case value 1: code to be executed;
Break;
Case value 2: the code to be executed;
Break;
Case value 3: code to be executed;
Break;
..........
Default: the code to be executed;
Break;
}
Execution Process: The program runs at the switch. First, the variable or expression value in the brackets is calculated, and then the value is matched with the value next to each case, once the matching is successful, the code in this case is executed. After the execution is complete, the break is encountered. Jump out of the switch-case structure. If it does not match the value of each case. Check whether default exists in the current switch-case structure. If default exists, execute the statement in default. If no default exists, the switch-case structure will not do anything.