Chapter III C # Loops and methods

Source: Internet
Author: User

First section 1-for Cycle introduction
Grammar:
for (conditional expression)
{
EXECUTE statement
}
Practice:
Chapter III Operations
1. Write a program to print values from 100 to 200;
2. Write a program to print from 10 to 1;
3. Write a program to print all even numbers between 10 and 30

Section II 2-declaration and assignment of variables, scope of variables

Section three for loops
Grammar:
while (conditional expression)
{
EXECUTE statement
}
Arithmetic progression 1+n=n* (n+1)/2

Fifth section while loop, first judge and then execute
1. A question during the interview
int i=0;
while (i<=5)
{
Console.WriteLine (i++);//Output 0 to 4, first take the value of I and then self-increment
Console.WriteLine (++i);//Output 1 to 5, first self-increment and then take the value of I
}

Section sixth do. While loop, perform a second judgment first, at least once
Grammar:
Do
{
EXECUTE statement
}
while (conditional expression)
1.break closing the nearest loop
2.continue Close the loop and proceed to the next cycle

Section Seventh Declaration and use of arrays
Grammar:
data type [] array name =new data type [number];
Int[] Arr=new int[5];

Eighth Section Array
When an int array is uninitialized, the default is 0
Default is null when an array of strings is not initialized

Introduction to the 12th section method
1. Method/function is a meaning
Method is a code snippet that can be reused
Overload: As long as the number of parameters or different types of parameters;
2. You cannot have overloaded methods that are just different names of parameters
3. Whether the method overload and the return value are irrelevant;

16th section variable-length array
The params must be the last parameter

Chapter III C # Loops and methods

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.