Chapter 2 Overview of C# Programming (Personal Study Notes)

1. Identifier , case sensitive

First character: a~z, A~Z, _ , @ are allowed, numbers are not allowed

Other characters: a~z, A~Z, 0~9, _ are allowed, @ is not allowed

@ can be placed in the first place, but is not recommended as a common character

2. Naming Conventions

Pascal case: used for type names and member names, with the first letter of each word in the identifier capitalized

Camel case: For local variables and method parameters, all words in an identifier except the first are capitalized

All caps: for abbreviations only

3. Keywords

Keywords cannot be used as variable names or other forms of identifiers unless they start with the @ character. All C# keywords consist of all lowercase letters, but .NET type names use the Pascal case convention


4. Format String

Console.WriteLine(“Two sample integers are{0} and {1}”,3,6);

{0} and {1} are surrogate tokens, 3 and 6 are surrogate values

The output is Two sample integers are 3 and 6

 

Console.WriteLine(“Three sample integersare {1},{0} and {1}”,3,6);

The output is Three sample integers are 6,3 and 6

 

Console.WriteLine(“Two sample integers are{2} and {1}”,3,6);

Running error, because there is no position 2 in the code, 3 is position 0, 6 is position 1


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324797883&siteId=291194637