Csharp language specification
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
1. Introduction 1
1.1 Hello world 1
1.2 Program structure 2
1.3 Types and variables 4
1.4 Expressions 6
1.5 Statements 8
1.6 Classes and objects 12
1.6.1 Members 12
1.6.2 Accessibility 13
1.6.3 Type parameters 13
1.6.4 Base classes 14
1.6.5 Fields 14
1.6.6 Methods 15
1.6.6.1 Parameters 15
1.6.6.2 Method body and local variables 16
1.6.6.3 Static and instance methods 17
1.6.6.4 Virtual, override, and abstract methods 18
1.6.6.5 Method overloading 20
1.6.7 Other function members 21
1.6.7.1 Constructors 22
1.6.7.2 Properties 23
1.6.7.3 Indexers 23
1.6.7.4 Events 24
1.6.7.5 Operators 24
1.6.7.6 Destructors 25
1.7 Structs 25
1.8 Arrays 26
1.9 Interfaces 27
1.10 Enums 29
1.11 Delegates 30
1.12 Attributes 31
2. Lexical structure 33
2.1 Programs 33
2.2 Grammars 33
2.2.1 Grammar notation 33
2.2.2 Lexical grammar 34
2.2.3 Syntactic grammar 34
2.3 Lexical analysis 34
2.3.1 Line terminators 35
2.3.2 Comments 35
2.3.3 White space 37
2.4 Tokens 37
2.4.1 Unicode character escape sequences 37
2.4.2 Identifiers 38
2.4.3 Keywords 39
2.4.4 Literals 40
2.4.4.1 Boolean literals 40
2.4.4.2 Integer literals 40
2.4.4.3 Real literals 41
2.4.4.4 Character literals 42
2.4.4.5 String literals 43
2.4.4.6 The null literal 45
2.4.5 Operators and punctuators 45
2.5 Pre-processing directives 45
2.5.1 Conditional compilation symbols 47
2.5.2 Pre-processing expressions 47
2.5.3 Declaration directives 48
2.5.4 Conditional compilation directives 49
2.5.5 Diagnostic directives 51
2.5.6 Region directives 52
2.5.7 Line directives 52
2.5.8 Pragma directives 53
2.5.8.1 Pragma warning 53
3.