Continue to update the second article:
1: Unary Operator: + +--
+ +: Whether it's pre-Gaga or post-gaga, the value of the variable will eventually be added to itself.
The difference between pre-and post-Gaga is manifested in the time of participating in the operation, if it is post-Gaga, first takes the original value to participate in the operation,
After the completion of the operation, and then add one, and the former Gaga is the first self-added, and then take a plus after the value of participating in the operation.
--whether it's a pre-or post-decrement, the value of the variable will eventually be reduced by itself.
+-*/% is a two-dollar operator, in an expression that has both a unary operator and a two-tuple operator, the unary operator should be evaluated first, and the unary operator should have precedence over the two-unary operators.
2: Compound assignment operator
+=:eg;a=a+5;=>a+=5;
-=:eg;a=a-5;=>a-=5;
*=: Ibid.
/=
%=
3: relational operator: Used to describe the relationship between the two (simply don't say much)
>
<
>=
<=
==
!=
An expression that is connected by a relational operator is called a relational expression, and each expression is able to solve a fixed value.
4:bool Type:
The bool type is used to describe the right or wrong, with a bool type of only two values: true false.
5: Logical Operator:
Logic and:&&
Let the user enter the old Soviet language and math results, output the following judgment is correct, correct output true, error output false
1) Lao Su's Chinese and maths scores are more than 90 points
Console.WriteLine ("Please input the old Soviet language results");
int Chinese = Convert.ToInt32 (Console.ReadLine ());
Console.WriteLine ("Please enter the mathematical results of Old su");
int math = Convert.ToInt32 (Console.ReadLine ());
BOOL B = chinese > && math > 90;
Console.WriteLine (b);
2) Language and mathematics have a door is greater than 90 points
BOOL B = chinese > 90 | | Math > 90;
Console.WriteLine (b);
Console.readkey ();
Logical OR: | |
The judgement of the year (according to one of the following two conditions):
The year can be divisible by 400. (2000)
The year can be divisible by 4 but not divisible by 100. (2008)
Let the user enter a year, and if it is run year, the output is true, and if not, the output is false.
Console.WriteLine ("Please enter a year");
int year = Convert.ToInt32 (Console.ReadLine ());
BOOL B = (year% 400 = = 0) | | (year% 4 = = 0 && Year% 100! = 0);
Console.WriteLine (b);
Console.readkey ();
Logical non-:!
Logic and logic or operators require placing a relationship expression or a value of type bool, with precedence higher than logical OR.
6: Grammatical structure
Sequential structure: from top to bottom.
Branching structure:
If structure,
Grammar:
if (judging condition): Judging the condition is generally a value of type bool or a relational expression or a logical expression
{
The code to execute;
}
Execution process:
When the program executes to the IF, it first determines if the judging condition with the if is set, and if so, returns True.
Executes the code in curly braces.
If the judging condition is not true, that is, return false, skip the curly brace directly.
Syntax features: First judge, then execute, it is possible that a code will not be executed.
Let the user enter the age, if the age of input is greater than 23 (including) years, then show the user that you are at the age of marriage.
Console.WriteLine ("Please enter your age");
int age = Convert.ToInt32 (Console.ReadLine ());
BOOL B = Age >= 23;
if (b)
{
Console.WriteLine ("You can get Married");
}
Console.readkey ();
If-else structure
Grammar:
if (judging condition)
{
The code to execute;
}
Else
{
The code to execute;
}
Execution process: The program runs to if, first of all to determine if the conditions of the If the condition is established, if established, then the execution
If the code in the curly braces is executed, it immediately jumps out of the if-else structure.
If the judging condition is not true, skip the curly brace with the IF, execute the code in the large enclosed by else, and after the execution is complete,
Jump out of the if-else structure.
Therefore, the IF-ELSE structure will execute at least one code.
Note: Else is always paired with the if closest to it
The user is required to enter two numbers a, B, if A and B are divisible or a plus B is greater than 100, the value of a is output, otherwise the value of output B
Console.WriteLine ("Please enter a value");
int a = Convert.ToInt32 (Console.ReadLine ());
Console.WriteLine ("Please enter the value of B");
int b = Convert.ToInt32 (Console.ReadLine ());
if ((a% b = = 0) | | (A + B) > 100)
//{
Console.WriteLine (a);
//}
Else
//{
Console.WriteLine (b);
//}
Select structure:
If ELSE-IF structure,
This result is used for multi-condition judgment, which means that one is chosen to execute in multiple judging conditions.
Grammar:
if (judging condition)
{
The code to execute;
}
else if (judging condition)
{
The code to execute;
}
else if (judging condition)
{
The code to execute;
}
else if (judging condition)
{
The code to execute;
}
Else
{
The code to execute;
}
Execution procedure: The program first determines whether the judging condition in the parentheses with the first if is true. If established,
Executes the code in the curly brace with the IF, and after the execution completes, jumps out of the current if else-if structure.
If the condition of the first if does not hold, continue to judge downward, and then determine whether the condition in each if is true.
If it is, execute the code in curly braces with the IF, and after execution, jump out of the if else-if structure. If
If the judging conditions for each if are not valid, see if there is an else in the current if ELSE-IF structure
If there is else, execute the code in else and, if not, jump out of the current structure and do nothing.
static void Main (string[] args)
{
Evaluation of students ' final exam results (consider using if or if-else good)//results >=90:a//90> results >=80:b//80> results >=70:c//70> results >=60:d//Results < ; 60:e
int score = 0;
BOOL B = true;
String level = "";
Console.WriteLine ("Please enter exam results");
Try
{
Score = Convert.ToInt32 (Console.ReadLine ());
If (score >= 90)
{
Level = "A";
}
else if (score >= 80)
{
Level = "B";
}
else if (score >= 70)
{
Level = "C";
}
else if (score >= 60)
{
Level = "D";
}
Else
{
Level = "E";
}
}
Catch
{
Console.WriteLine ("Incorrect input, program exit");
b = false;
}
if (b)
{
Console.WriteLine (level);
}
Console.readkey ();
Console.readkey ();
}
(Demo includes Try-catch)
Switch-case structure.
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
Case Value 4: the code to execute;
Break
.....
Default
The code to execute;
Break
}
Execution procedure: The program first calculates the value of a variable or expression in a switch parenthesis.
Take the calculated values in turn to match the values in each case.
If the match succeeds, the code with the case is executed, and after execution is completed, a break is encountered,
Jump out of the current switch-case structure.
If it does not match the value of each case, see if there is a default in the current switch-case.
If default is present, the code in default is executed, and if there is no default, the struct does nothing.
(
If the judgment of the multi-condition, is an interval of judgment. It is recommended to use if else-if.
If you are judging a multi-condition fixed value. It is recommended to use Switch-case.
)
Test results//Results >=90:a//90> results >=80:b//80> results >=70:c//70> results >=60:d//Results <60:e
Console.WriteLine ("Please enter exam results");
int score = Convert.ToInt32 (Console.ReadLine ());
String level = "";
Switch (SCORE/10)
{Case 10:case 9:
Level = "a";
Break Case 8:
Level = "B";
Break Case 7:
level = "C";
Break Case 6:
Level = "D";
Break
Default
Level = "E";
Break }
Console.WriteLine (level);
cyclic structure: the so-called cycle, refers to the same thing is not kept. Even if it is a loop, it will end, and if a loop never ends, this cycle is called the Dead loop.
While Loop,
Syntax for While loop:
while (looping condition) value of type//bool, relational expression, logical expression
{
The loop body;//refers to the thing that keeps on doing
}
Execution procedure: When the program executes to the while, first determine whether the loop condition in the while parenthesis is true.
If the loop condition is true, that is, the loop body in the while brace is executed when the loop body
After the execution, we return to the loop condition to continue to judge, if the loop condition is established, then continue to execute the loop body,
If the loop condition is not true, immediately jumps out of the current while loop.
In a loop, there is always a line of code that can change the loop condition so that it ceases to be true one day,
If there is not a single line of code that can change the loop condition, then this loop is called the Dead loop.
The most common dead loops:
while (true)
{
}
The Break keyword
1), jump out of the current switch-case structure
2), can jump out of the current cycle
Break is used most often with a while (true) dead loop
Ask for 1-100 between all integers and 1-100 for all odd numbers and 1-100 for all even-numbered and
Loop body: Keep adding.
Cycle condition: Not yet added to 100
int sum = 0;//sum
int i = 1000;
while (I <= 100)
//{
if (i% 2 = = 0)
// {
sum + = I;//sum=sum+i;
// }
i++;
//}
Console.WriteLine (sum);
Console.readkey ();
Do-while Cycle,
Grammar:
Do
{
Circulation body;
}while (cyclic conditions);
Execution process:
The program first executes the loop body in do, and after execution completes, with the result of execution to determine whether the loop condition is established.
If this is true, the loop body in do is continued, and if not, the Do-while loop is popped out.
Features: First execution, then judge, at least to perform the cycle of the body.
static void Main (string[] args)
{
Tomorrow Xiao Lan will be on the stage, the teacher said the song of tomorrow's performance to sing again, if satisfied, Xiao Lan can go home. Otherwise it will need to be practiced again until the teacher is satisfied. (y/n)
Circulation body: Xiao Lan sing once ask the teacher are you satisfied? The teacher answered
Cycle Condition: Teacher Dissatisfied
Console.WriteLine ("Teacher, I sing this again, are you satisfied?") ");
String answer = Console.ReadLine ();
while (answer = = "No")
//{
Console.WriteLine ("Teacher, I sing again, are you satisfied?") ");
Answer = Console.ReadLine ();
//}
Console.WriteLine ("Satisfied, you can go Home");
String answer = "";
Do
{
Console.WriteLine ("I sing this again, teacher are you satisfied?") ");
Answer = Console.ReadLine ();
} while (answer = = "no");
Console.readkey ();
}
For Loop,
Function: a loop designed to handle the number of known cycles.
Grammar:
for (expression 1; expression 2; expression 3)
{
Circulation body;
}
Execution process:
First, the expression 1 is executed, the loop variable is declared, and then the expression 2 is executed to determine whether the loop condition is true.
In the first loop, the expression 3 is not executed, but it goes directly into the loop execution loop body.
After the loop body executes, execute expression 3, and then execute expression 2 to determine if the loop condition is true,
If it is, the loop body is resumed, and if not, the current for loop is popped out.
Find out the number of daffodils in 100-999?
Narcissus number: The current hundred number of the hundred cubic + 10-bit cubic + digit cubic = = Current this hundred number
153 1 + 125 + 27=153
153
Hundred: 153/100
10-bit: 153%100/10
Digit: 153%10
3*3*3
GC Garbage Collection
for (int i = +; I <= 999; i++)
{
int bai = i/100;
int shi = i% 100/10;
int GE = i% 10;
if (Bai * bai) bai + shi * shi * shi * ge * GE * ge * = i)
{
Console.WriteLine (i);
}
}
Console.readkey ();
foreach Loop
About The Foreach loop can look at this simple demo: Dream break Hard to find C # foreach Loop traversal array
7:try-catch Exception Capture
Grammar:
Try
{
There is a possibility that the exception code will appear;
}
Catch
{
Code to execute after an exception occurs;
}
Execution process:
If the code in the try has an exception, then this line of exception code, even if there are 100 lines of code, will no longer be executed.
Instead, jump directly into the catch and execute the code in the catch.
Conversely, if the code in the try does not have an exception, the catch code is not executed;
(Try-catch finally , it means that if you add finally, the code in finally must be executed)
static void Main (string[] args)
{
int number = 0;
BOOL B = true;
Console.WriteLine ("Please enter a number, we will print this number twice times");
Try
{
Number = Convert.ToInt32 (Console.ReadLine ());//50a
Console.WriteLine ("La La La");
Console.WriteLine ("La La La");
Console.WriteLine ("La La La");
Console.WriteLine ("La La La");
}
Catch
{
Console.WriteLine ("The number entered is incorrect, the program exits!!!!");
b = false;
}
if (b)
{
Console.WriteLine (number * 2);
}
Console.readkey ();
}
8: Scope of local variables
In the main function, all the variables declared are called local variables. The scope of a local variable is scoped.
The so-called scope refers to the ability to use the scope of the variable (for example, the curly braces can be considered a scope).
(Temporarily this point all the demo is the most basic hope to understand, may be typesetting a bit of a problem, but also hope patience.) If there is something wrong in the place also hope to advise. )
2015-04-01
36E
Finally, I wish you a happy April Fools ' Day!
General review of C # Fundamentals 02