C # review ③,

Source: Internet
Author: User
Tags case statement switch case

C # review ③,

C # review ③

June 16, 2016

11: 13

Main Declaration& StatementDeclarations and statements

1.What is the declarative space contained in a program?

Namespace: declarations of classes, interfaces, structs, enums, delegates

Namespace: Declaration class, interface, struct, enumeration, delegate

Class & interface & struct: declarations of fields, methods...

Class & Interface & struct: Declares fields and methods.

Enumeration: declarations of enumeration constants

Enumeration: declares an enumeration constant.

Method block: declarations of local variables

Method block: declare local variables

2.Rules:

Domain rules:

No name may be declared more than once in the same declaration space cannot have the same name in the same declarative space.

However, it may be redeclared in an inner declaration space (Login T in a nested statement block)

However, the same name can be declared multiple times in an internal nest.

Visibility rules:

Names declared in a method are visible from their declaration until the end of the method. the lifecycle of a name declared in a method starts from the declaration to the end of the method.

If a name is redeclared in an inner declaration space, it hides the same name from the outer declaration space. if an internal nested declaration space has the same name as an external space, the name will overwrite the external name.

In general, no name is visible outside its declaration space. Generally, no name can be visible outside its declared space.

3. NamespaceNamespace

Other Namespaces can be nested, and multiple enumerations, classes, and interfaces can be contained in the namespace;

When a nested namespace exists, the internal namespace must be obtained by adding the dot "." operator to the external namespace.

4. Classes& Interface & Structs & EnumerationClass, interface, struct, and enumeration

5. Statement BlocksDeclare Block

It can include multiple parallel scopes and nested scopes.

6. Declaration of Local VariablesDeclare local variables

Local variables overwrite global variables and space for different variables

7. Simple StatementSimple statement

Empty statement;

Value assignment statement sum + = x;

Method call: string [] parts = s. Split (',');

8. if Statement ifStatement

9. switch Statement switchStatement

Can be used as the jump expression type: integer type, char, enum

The switch case statement applies to selecting an Execution Branch from a group of mutually exclusive branches.

It is worth noting that the case value must be a constant expression and cannot be a variable.

In C #, an interesting part of the switch statement is that the emissions of the case clause are more flexible, and the default clause can even be placed at the beginning (because neither case can be the same ).

10. LoopsLoop statement

While loop statement

Do while LOOP

For Loop

11. foreach Statement foreachStatement

12. JumpJump statement

13. return StatementReturn Statement

14. output to the ConsoleOutput to console

15. Formatting Codes for numbersNumber formatting

16. Formatted Output to a FileFormat output to file

17. Keyboard InputKeyboard Input

18. Input from a FileRead from File

19. Reading Command-Line ParametersREAD command line parameters

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.