Learning Note 3 operators and expressions

Source: Internet
Author: User

1. Self-added and self-reduced budget
(1) int age = 18;
Int sum = age ++-10;
The result is age = 19; sum = 8;
(2)
Int age = 18;
Int sum = ++ age-10;
The result is age = 19; sum = 19;
The auto-subtraction operation has the same meaning.
The unary operator (++ --) has a higher priority than the binary operator.
2. in C #, there are six Relational operators used to compare the relationships between two things. They are >,<,=, and ,! =, >=, <=.
3. Relational computation results are of the bool type. The bool type has only two values: true and false.
4. logical operators &, | or ,! (Non, unary operator)
Logic and operation (the results on both sides are of the bool type, usually relational expressions, and the results of the entire logic and budget are also of the bool type): &; expression 1 & Expression 2
Note: The logic and priority are greater than the logic or priority.
5. If judgment structure:
Basic Syntax: If (Condition Statement)
Statement;
Execution Process: first, judge the result of the condition. If the condition is true, execute Statement 1. If the condition is false, skip Statement 1 and execute the following statement.
Note: 1) the condition following the if clause must be calculated as a bool value.
2) by default, the IF statement can only contain one sentence, that is, the statement associated with the if statement is only statement 1.
6. Forced type conversion: (data type name) converted value
7. In the IF-else if statement, the next if statement is entered and the condition judgment after the if statement is performed only when a condition is not met, once the condition after an if statement is true, the statement included in the IF statement is executed. After the statement is executed, the program jumps out of the IF-else if structure. If none of the if conditions are true, the last else statement is executed. (if no else exists, nothing is executed .)
8. Switch-case statement:
Syntax:
Switch (expression)
{
Case value 1: Statement Block 1;
Break;
Case value 2: Statement Block 2;
Break;
Default: Statement block 3;
Break;
}
9. Execution Process: Calculate the expression first, and then execute the statement that matches the value following the matching case based on the calculation result. If there is a matching item, until the break statement jumps out of switch-case, if all the case values do not match, if default exists, execute the statement after default until the break ends. If no, switch-case exists and do not execute anything.
Example: String input = console. Readline ();
Decimal salary = 5000;
Bool flag = false;
Switch (input)
{
Case "":
Salary + = 500;
Break;
Case "B ":
Salary + = 200;
Break;
Case "C ":
Salary-= 200;
Break;
Default:
Console. writeline ("your input is incorrect ");
Flag = true;
Break;
}
If (flag = false)
Console. writeline (salary );
Console. readkey ();
10. Comparison between switch-case and if-else if
Switch: Generally, it can only be used for equivalent comparison.
If-Else: can process range comparison

 

<A href = "http://net.itheima.com/" target = "blank"> Windows Phone 7 </a>, <a href = "http://net.itheima.com/" target = "blank">. net training </a>. We are looking forward to communicating with you!

Related Article

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.