One. Select structure:
1. If selection structure
2. IF-ELSE selection Structure
3. If-else If-else if-else Multiple if selection structure
4. If-if-else-else Nested IF selection structure
5. Switch selection structure
switch (expression)
{
case constant Expression 1:
Statement 1;
Break
Case constant Expression 2:
Statement 2;
Break
.................
Default
Statement N;
Break
}
Note: The switch selection structure in C # must have Braek in the case, otherwise the error will be prompted!
Note points for using case phrases:
1. Case clauses are not ordered in sequence and can be arbitrarily adjusted
2. Any two case statements cannot have the same value
3. The value in case must be a constant expression, no variable is allowed
Two. Object array:
1. Creating an array of objects
Object array type [] Object array name =new object array type [array length];
Student [] stus=new Student ();
2. Iterating through an array of objects
foreach (Traversal of the resulting type variable name in the object array name)
foreach (Student stu in Stus) {
Stu. Showinfo ();
}
Three. Loop structure:
1. While loop: first judgment and execution
while (loop condition) {
Loop body
}
2. Do-while cycle: First to perform a loop body, and then determine the cycle conditions
do{
Loop body
}while (cyclic condition)
3. For loop
for (int i=0;i<=10;i++) {
Loop body
}
4. Double loop: Outer loop executes once, Inner loop executes one week
Four. Bubble sort
Bubble sort Shorthand formula (ascending):
N numbers to queue up
22 compared to a small front
Outer Loop N-1
Inner-layer Cyclic n-1-i
Int[] scores = new Int[5] {16, 25, 9, 90, 23};
for (int i = 0; I < scores. Length-1; i++)
{
for (int j = 0; J < scores. Length-1-I; J + +)
{
if (Scores[j] > scores[j + 1])
{
int temp = 0;
temp = scores[j + 1];
Scores[j + 1] = Scores[j];
SCORES[J] = temp;
}
}
}
foreach (int score in scores)
{
Console.Write (score+ "\ t");
}
Console.ReadLine ();
Basic syntax for C #