C # basic notes (Day 4 ),

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.