15-01-02 C # syntax 04

Source: Internet
Author: User
Tags switch case

Exception: There is no syntax error, and during program run, due to some reason the program has an error and can no longer run properly.

If you want the program to become more robust, you should often use Try-catch to catch exceptions in your code.

Which line of code is likely to be an exception, you try it, try{} catch{}

Execution procedure: If the code in the try does not have an exception, the code in the catch will not execute, and if the code in the try has an exception, 100 lines of code will not be executed after the code for the exception is present.
Instead, jump directly into the catch to execute the code

The scope of the variable is that you can use the range of the variable, the scope of the variable is generally from the curly brace that declares it to the end of the curly brace that corresponds to the end of the curly braces in this range, we can access and use the variable, beyond this range to access the

The bool type is used if the code satisfies certain conditions to execute

No other code can be written between try and catch

Switch (the value of a variable or an expression)
{
Case value 1: the code to execute;
Break
Case Value 2: the code to execute;
Break
Case Value 3: the code to execute;
Break
......
Dafault: the code to execute;
Break
}

Break can jump out of switch-case structure

When you press ctrl+k+s after selecting all the code, you will be prompted

Switch case can do, if-else if must be able to do, but if-else if can do, switch case not necessarily can do

Switch (the value of a variable or an expression)
{
Case value 1:
Case Value 2: the code to execute;
Break
The code that CASE1 and Case2 want to execute is the same.
}

The switch expression must be a bool,char,string,int, an enumeration, or a corresponding nullable type;

Some brackets you don't know which one, you can comment on it later

After the program code is finished, consider the exception globally

while (loop condition)
{
Circulation body;
}

When debugging, the yellow arrows tell you that this line of code is about to be executed.

When debugging, there is a watch 1 window, in the name you can enter to monitor the variable name or expression name, in the following values will show the current value

The function of break, 1. Can jump out of the switch-case structure, 2. Can jump out of the current loop

Break is generally not used alone, but is used with the If judgment, indicating that when certain conditions are met, it is no longer recycled.

In the writing loop, the first thing to consider is what the loop body is, and what the loop condition is.

Do-while loops can do, while loops can do

Do
{
Circulation body;
}while (cyclic conditions);

15-01-02 C # syntax 04

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.