C # Quick Warm up

Source: Internet
Author: User

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 ();

C # Quick Warm up

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.