Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
CSharp 4 Language Specification.doc
Скачиваний:
0
Добавлен:
01.05.2025
Размер:
2.51 Mб
Скачать

C#

Language Specification

Version 4.0

Notice

© 1999-2010 Microsoft Corporation. All rights reserved.

Microsoft, Windows, Visual Basic, Visual C#, and Visual C++ are either registered trademarks or trademarks of Microsoft Corporation in the U.S.A. and/or other countries/regions.

Other product and company names mentioned herein may be the trademarks of their respective owners.

Table of Contents

Notice 2

1. Introduction 1

1.1 Hello world 1

1.2 Program structure 2

1.3 Types and variables 4

1.4 Expressions 7

1.5 Statements 9

1.6 Classes and objects 14

1.6.1 Members 15

1.6.2 Accessibility 15

1.6.3 Type parameters 15

1.6.4 Base classes 16

1.6.5 Fields 16

1.6.6 Methods 17

1.6.6.1 Parameters 17

1.6.6.2 Method body and local variables 19

1.6.6.3 Static and instance methods 19

1.6.6.4 Virtual, override, and abstract methods 20

1.6.6.5 Method overloading 23

1.6.7 Other function members 23

1.6.7.1 Constructors 25

1.6.7.2 Properties 26

1.6.7.3 Indexers 26

1.6.7.4 Events 27

1.6.7.5 Operators 27

1.6.7.6 Destructors 28

1.7 Structs 28

1.8 Arrays 29

1.9 Interfaces 31

1.10 Enums 32

1.11 Delegates 34

1.12 Attributes 35

2. Lexical structure 37

2.1 Programs 37

2.2 Grammars 37

2.2.1 Grammar notation 37

2.2.2 Lexical grammar 38

2.2.3 Syntactic grammar 38

2.3 Lexical analysis 38

2.3.1 Line terminators 39

2.3.2 Comments 39

2.3.3 White space 41

2.4 Tokens 41

2.4.1 Unicode character escape sequences 41

2.4.2 Identifiers 42

2.4.3 Keywords 44

2.4.4 Literals 44

2.4.4.1 Boolean literals 44

2.4.4.2 Integer literals 45

2.4.4.3 Real literals 46

2.4.4.4 Character literals 46

2.4.4.5 String literals 47

2.4.4.6 The null literal 49

2.4.5 Operators and punctuators 49

2.5 Pre-processing directives 49

2.5.1 Conditional compilation symbols 51

2.5.2 Pre-processing expressions 51

2.5.3 Declaration directives 52

2.5.4 Conditional compilation directives 53

2.5.5 Diagnostic directives 55

2.5.6 Region directives 56

2.5.7 Line directives 56

2.5.8 Pragma directives 57

2.5.8.1 Pragma warning 57

3. Basic concepts 59

3.1 Application Startup 59

3.2 Application termination 60

3.3 Declarations 60

3.4 Members 62

3.4.1 Namespace members 63

3.4.2 Struct members 63

3.4.3 Enumeration members 63

3.4.4 Class members 63

3.4.5 Interface members 64

3.4.6 Array members 64

3.4.7 Delegate members 64

3.5 Member access 64

3.5.1 Declared accessibility 64

3.5.2 Accessibility domains 65

3.5.3 Protected access for instance members 67

3.5.4 Accessibility constraints 68

3.6 Signatures and overloading 69

3.7 Scopes 71

3.7.1 Name hiding 73

3.7.1.1 Hiding through nesting 73

3.7.1.2 Hiding through inheritance 74

3.8 Namespace and type names 75

3.8.1 Fully qualified names 77

3.9 Automatic memory management 78

3.10 Execution order 81

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]