C # and. NE Study Day Fourth

Source: Internet
Author: User

(mainly the notes of the Zhaojianyu teacher of the Preach Wisdom Podcast, due to the lessons of these days and the previous C-C language and C + + almost all have learned all began to jump, here to thank Zhaojianyu Teacher)

1. Abnormal capture
We often have a variety of anomalies in the program, if you want your program to become stronger.
You should use Try-catch frequently for exception trapping in your code.

Which line of code is likely to be abnormal, you kick it one foot.
Grammar:
Try
{
Code that may appear to be abnormal;
....
...
...
}
There can be no other code between try and catch
Catch
{
Code to execute after an exception occurs;
}

Execution procedure: If the code in the try does not have an exception, the code in the catch will not execute.
If there is an exception to the code in the try, then there are 100 lines behind the code that is not going to execute the exception.
Instead, jump directly into the catch to execute the code


2. Scope of variables
The scope of a variable is the extent to which you can use the variable.
The scope of a variable is usually the end of the parenthesis that declares it, starting at the end of the parenthesis that corresponds to it.
Within this range, we can access and use variables. Beyond this range, there's no access.


3, Switch-case
The judgment used to deal with the fixed value of multiple conditions.
Grammar:
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
..........
Default: The code to execute;
Break
}
Execution procedure: The program executes to switch, first the value of the variable or expression in parentheses is calculated,
Then take this value to match the value followed by each case, and once the match succeeds, it executes
The case takes the code, and after execution finishes, it encounters a break. Jump out of the switch-case structure.
If it does not match the value that is taken with each case. Depends on whether the current switch-case structure exists.
Default, if there is default, the statement in default is executed, and if there is no default, the switch-case structure
Don't do anything.

4. Cyclic structure
While loop:
while (loop condition)
{
Circulation body;
}
Execution procedure: When the program runs to the while, first determine if the loop condition in the parentheses with the while is true,
If it is true, that is to say, return one, then execute the loop body, execute the loop body again, and return to
The loop condition is judged, if it is still true, the loop body is continued, and if it is not, it jumps out of the while loop.
In the while loop, there is always a line of code that can change the cycle condition, so that one day no longer holds,
If there is not a single line of code that can change the loop condition, that is, the loop condition is always set, and we call this loop
Called the cycle of death.
The simplest of the most commonly used dead loops:
while (true)
{

}

Features: first judgment, then execution, it is possible that the cycle is not executed.
5. Break
1), can jump out of switch-case structure.
2), you 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.

6, Do-while cycle.
Grammar:
Do
{
Circulation body;
}while (cyclic conditions);
Execution procedure: The program first executes the loop body in do, after the execution completes, to judge the do-while circulation condition,
If this is true, the loop body in do is continued, and if not, the Do-while loop is popped out.
Features: First cycle, then judge, at least to perform the loop body.

C # and. NE Study Day Fourth

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.