The first three chapters of C # That we have learned in those years,

Source: Internet
Author: User

The first three chapters of C # That we have learned in those years,

Chapter 1

1. main method of c #

The return value can be void or int.

Four Main () methods:

Static void Main (){}

 

Static void Main () {string [] args}

 

Static int Main (){}

 

Static int Main () {string [] args}

2. C # VARIABLES

Common Data Types in c #: integer int, float, and string Boolean bool

Naming rules for variables in c:

1, composition: English letters, numbers, "_"

2, start with: English letter, "_"

3. Keywords cannot be used;

 

3. constants and variables in C #

Variable: variable amount

For example:

Int num = 5;

Num = 7;

 

Constant: Once defined, its value cannot be modified in subsequent code.

For example:

Int num = 5;

 

4. Massive code folding

The shortcut key is Ctrl + K + S.

Const data type constant name = value;

Note: constants cannot be re-assigned.

Constants must be initialized during declaration.

Constant naming rules: 01, meaningful 02, both large write 03, length should be long

 

5. Input and Output

Output to the console:

Console. WriteLine () method -- line feed after output

Console. WriteLine

For example: Console. WriteLine ("My course name is: {0}", course );

{0} is a placeholder

Use {0}, {1}, and {2} in turn to correspond to the variables in the Variable list

 

Read from the console:

Console. ReadLine ();

 

6. Access Modifier

Access modifiers: such as public and private

Return type: such as int, double, string, void, etc.

 

Comments in 7. c #

Single line comment ://

Multi-line comment :/**/

Document Note :/**

*/

Chapter 2

1. c #AndJavaOfSwitchWhat are the differences in statement usage?

01. in java, the expression value after switch can only be (int/char), but the value in c # Can Be (int/char/string)

02. There can be no break statement after case in java, but not in c #.

 

2.IfCondition Structure

C # is exactly the same as java

 

3. Array

Int [] num = new int [5] {0, 1, 2, 3, 4 };

Int [] num = new int [] {0, 1, 2, 3, 4}; omitted Length

Int [] num = {0, 1, 2, 3, 4}; omitting new

In C #, the length of an array can be omitted, while that of new.

Elements in the loop output Array

For (int I = 0; I <array. Length; I ++) // output all elements in the array

{

Console. WriteLine (array [I]);

}

4. Use foreach to traverse array elements cyclically

A foreach loop is generally used to traverse the entire array.

Syntax: foreach (element type variable name in set or array name)

{

// Statement

}

5. Double Loop

Int I, j; // cyclic variable

For (I = 1; I <= 5; I ++)

{

// The number of numbers printed per line is controlled cyclically in the inner layer

For (j = 1; j <= I; j ++)

{

Console. Write (j );

}

Console. WriteLine ();

}

 

6.Bubble Sorting

Rule: compare two adjacent numbers each time, small switches to the front, and the maximum number after each wheel speed switches to the maximum

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.