C # Basic Class notes

Source: Internet
Author: User
Tags arithmetic operators bitwise bitwise operators case statement clear screen variable scope

Chapter III: Operators and expressions

1. Knowledge operator : operator, also known as operator, is a symbol applied to an operation that acts on one or more operands
Classification of operators:
(1) by Operation Quantity
The unary (mesh) operator acts on one operand
The binary (mesh) operator acts on two operands
The ternary (mesh) operator acts on three operands
(2) function by operator
Arithmetic operators for mathematical operations
Logical operators are used to determine true and false
Bitwise operators are used in binary operations
Other ...

2. Common operators: Parentheses
Function: (1) type conversion (2) Change Order of operation (3) function call writing method: English parenthesis ();

3. Common operators: Arithmetic operators
Gaga (+ +) operator
Writing method: Variable name + + 1. Calculates the return result, same as the variable (calculates the return result of the entire statement) 2. Increment the value of a variable by 1
+ + variable Name 1. Calculates the return result of the entire statement, adding 1 2 to the value of the variable. Increment the value of the variable by 1
Decrement (-) operator
Writing method: Variable name--1. Calculates the returned result, same as the variable 2. Subtract the value of a variable by 1
--Variable Name 1. Calculates the variable result, minus 1 2 for the variable value. Subtract the value of a variable by 1
Order of Operation: (+ +) (-) (*) (/) (%)  (+) (-)
4. Common operators: Assignment operators
Assignment operator: = + = = *=/=%= return result same as variable value

5. Common operators: Logical operators

Definition: Common logical operators for operators that determine whether conditions are true: = =/= > >= < <= && | | !
&& (and): two bool types for operation. The result of the operation: True is true, the other is False
|| (OR): two bool types for operation. Result of the operation: false false for false other for true
! (non): unary operator, negation of data of a bool type, true data, false operation result, false data, true operation result


6. Common operators: three mesh operators
Definition: The three-mesh operator is also called the ternary operator, which requires three operands to participate in the operation of the notation: operand 1? Operand 2: Operand 3 (operand 1 must be of type bool, operand 2 operand 3 can be of any type, but must be of two type)

Returns the result: if the operand 1 determines that the result is true, the operand 2 is returned as a result if the operand 1 determines that the result is false, the operand 3 is returned as the result

7. Bitwise operators
Definition: For operations on a digital binary
& (with): two digit binary format for each bit comparison if all 1 take 1, otherwise take 0
| (OR): compare each one, if all is 0, take 0, otherwise take 1
^ (also or): For each comparison, the same takes 0, different take 1
<< (left shift): Moves the specified number of digits to the left of a binary number
>> (left shift): shifts the specified number of digits to the right of a binary number
~ (FETCH): A unary operator that turns 0 on the number bits to 1 1 to 0

8. Expressions
Definition: A meaningful statement that contains at least one operand and every expression of a single operator, with a return type each expression can be manipulated with other expressions as long as the type meets the requirements

9. Operator Precedence
Operators with higher precedence are given precedence over operators with the same precedence, executed from left to right
Common scenarios that use multiple operators
Assignment operation: Always last execution
The assignment operator. Png
Mathematical operations: In accordance with the mathematical sequence of operations, first run the parentheses, there are nested from the inside to the outside of the run, then run multiplication, and finally run the addition and subtraction
Logical operation: When the logical operation, the && and | | Expressions at both ends of a symbol as a whole
A>b && c>d says: a > B and C > B
A<b | | C<d says: A<b or C<d
Other: Use parentheses or separate writing to control the order of operations when the sequence of operations is unclear, and the parentheses have the highest precedence
Type conversions and function calls: The type conversions here refer to the Display transformation (target type)
(target type) x.y () First make a function call to convert the result of a function call to a type conversion


4th Chapter Process Control


1. Variable Scope
Definition: It can be simply understood as the parentheses in which a variable is defined, and within curly braces, the variable is valid and outside the curly brace
When defining a variable in a location, the variable must not be the same as the variable name covered by the scope
In C #: Curly braces cannot be variable declaration statements when you omit curly braces

2.switch selection
The switch statement can be converted to the if structure, or the IF structure may not be converted to the switch format
Code format:
"Break" must write code 1; Code 2; must be a specific value
The values of code 1 and code 2 must be compared to (variables and expressions)
A case statement can have any number of
The default statement can be written or not written, 0 or 1


3.while Cycle
Loop body (any function, code of any data) loop body If there is only one sentence, you can omit the curly brace
The whole while statement means: If the loop condition is true, then the loop body is executed, the loop body is executed, then the condition is true, if true, then the loop body is executed, and then the condition is true, then it goes on until the result of the loop condition is false, and the loop is ended.


 4. do while loop
  do while loop: You can omit some duplicate code to make the entire code cleaner
    Code format:
   statement meaning: First execute the loop body, and then determine whether the loop condition is satisfied, if satisfied then execute the loop body again, and then determine whether the condition is satisfied, until the condition is not satisfied, and then end the loop

 5.for Loop
   code format
   statement run meaning: Run expression 1 to determine if the loop condition is true, if true, then execute the loop body, after execution, then run Expression 2, Then judge the cycle conditions ..... The loop will not end until the loop condition is false
   expression 1: Can be any code, must be executed, and only once
   expression 2: Can be any code that executes after the loop body executes the
   Region directive: Region and Endregion must be written in pairs, that is, you cannot write only one region or write only one endregion, and they all start with a # number.
   Console Clear screen: Sometimes, when the program runs to some point, we need to clear the current contents of the console, this time, you need to use the console to clear the command.


6.break and Continue
Break
(for switch) break can be used in switch selection and looping
(for loops) means to end the loop immediately
Continue can only be used for loops that immediately end when the secondary loop enters the next loop
7. Finding problems
Find the data you need, based on your needs, in a set of data
Simple find: In a sample, look for the target data at once
Features: Must be used to the loop, the cycle must be from the first data of the sample, after reaching the end of the last data of the sample, the loop body must contain a judgement, the judgment is used to determine whether the current data is the target data




C # Basic Class notes

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.