SKIP THE SHIPPING
Use code NOSHIP during checkout to save 40% on eligible eBooks, now through January 5. Shop now.
Register your product to gain access to bonus material or receive a coupon.
This eBook includes the following formats, accessible from your Account page after purchase:
EPUB The open industry format known for its reflowable content and usability on supported mobile devices.
PDF The popular standard, used most often with the free Acrobat® Reader® software.
This eBook requires no passwords or activation to read. We customize your eBook by discreetly watermarking it with your name, making it uniquely yours.
“Based on my own experience, I can safely say that every .NET developer who reads this will have at least one ‘aha’ moment and will be a better developer for it.”
–From the Foreword by Don Box
The popular C# programming language combines the high productivity of rapid application development languages with the raw power of C and C++. Now, C# 3.0 adds functional programming techniques and LINQ, Language INtegrated Query. The C# Programming Language, Third Edition, is the authoritative and annotated technical reference for C# 3.0.
Written by Anders Hejlsberg, the language’s architect, and his colleagues, Mads Torgersen, Scott Wiltamuth, and Peter Golde, this volume has been completely updated and reorganized for C# 3.0. The book provides the complete specification of the language, along with descriptions, reference materials, code samples, and annotations from nine prominent C# gurus.
The many annotations–a new feature in this edition–bring a depth and breadth of understanding rarely found in any programming book. As the main text of the book introduces the concepts of the C# language, cogent annotations explain why they are important, how they are used, how they relate to other languages, and even how they evolved.
This book is the definitive, must-have reference for any developer who wants to understand C#.
Foreword xi
Preface xiii
About the Authors xv
About the Annotators xvii
Chapter 1: Introduction 1
1.1 Hello, World 2
1.2 Program Structure 4
1.3 Types and Variables 6
1.4 Expressions 10
1.5 Statements 13
1.6 Classes and Objects 18
1.7 Structs 41
1.8 Arrays 43
1.9 Interfaces 46
1.10 Enums 48
1.11 Delegates 49
1.12 Attributes 53
Chapter 2: Lexical Structure 55
2.1 Programs 55
2.2 Grammars 55
2.3 Lexical Analysis 57
2.4 Tokens 61
2.5 Preprocessing Directives 74
Chapter 3: Basic Concepts 87
3.1 Application Start-Up 87
3.2 Application Termination 88
3.3 Declarations 89
3.4 Members 92
3.5 Member Access 95
3.6 Signatures and Overloading 104
3.7 Scopes 106
3.8 Namespace and Type Names 112
3.9 Automatic Memory Management 116
3.10 Execution Order 121
Chapter 4: Types 123
4.1 Value Types 124
4.2 Reference Types 135
4.3 Boxing and Unboxing 137
4.4 Constructed Types 141
4.5 Type Parameters 145
4.6 Expression Tree Types 146
Chapter 5: Variables 149
5.1 Variable Categories 149
5.2 Default Values 154
5.3 Definite Assignment 155
5.4 Variable References 171
5.5 Atomicity of Variable References 172
Chapter 6: Conversions 173
6.1 Implicit Conversions 174
6.2 Explicit Conversions 180
6.3 Standard Conversions 188
6.4 User-Defined Conversions 188
6.5 Anonymous Function Conversions 193
6.6 Method Group Conversions 200
Chapter 7: Expressions 203
7.1 Expression Classifications 203
7.2 Operators 206
7.3 Member Lookup 214
7.4 Function Members 217
7.5 Primary Expressions 238
7.6 Unary Operators 280
7.7 Arithmetic Operators 285
7.8 Shift Operators 295
7.9 Relational and Type-Testing Operators 297
7.10 Logical Operators 307
7.11 Conditional Logical Operators 309
7.12 The Null Coalescing Operator 311
7.13 Conditional Operator 313
7.14 Anonymous Function Expressions 314
7.15 Query Expressions 324
7.16 Assignment Operators 339
7.17 Expressions 344
7.18 Constant Expressions 344
7.19 Boolean Expressions 346
Chapter 8: Statements 347
8.1 End Points and Reachability 348
8.2 Blocks 350
8.3 The Empty Statement 351
8.4 Labeled Statements 352
8.5 Declaration Statements 353
8.6 Expression Statements 357
8.7 Selection Statements 358
8.8 Iteration Statements 364
8.9 Jump Statements 373
8.10 The try Statement 380
8.11 The checked and unchecked Statements 385
8.12 The lock Statement 385
8.13 The using Statement 387
8.14 The yield Statement 390
Chapter 9: Namespaces 393
9.1 Compilation Units 393
9.2 Namespace Declarations 394
9.3 Extern Aliases 395
9.4 Using Directives 396
9.5 Namespace Members 403
9.6 Type Declarations 403
9.7 Namespace Alias Qualifiers 404
Chapter 10: Classes 407
10.1 Class Declarations 407
10.2 Partial Types 420
10.3 Class Members 429
10.4 Constants 443
10.5 Fields 445
10.6 Methods 455
10.7 Properties 478
10.8 Events 491
10.9 Indexers 498
10.10 Operators 503
10.11 Instance Constructors 510
10.12 Static Constructors 518
10.13 Destructors 520
10.14 Iterators 522
Chapter 11: Structs 537
11.1 Struct Declarations 537
11.2 Struct Members 539
11.3 Class and Struct Differences 539
11.4 Struct Examples 547
Chapter 12: Arrays 553
12.1 Array Types 553
12.2 Array Creation 555
12.3 Array Element Access 556
12.4 Array Members 556
12.5 Array Covariance 556
12.6 Array Initializers 557
Chapter 13: Interfaces 561
13.1 Interface Declarations 561
13.2 Interface Members 564
13.3 Fully Qualified Interface Member Names 569
13.4 Interface Implementations 570
Chapter 14: Enums 585
14.1 Enum Declarations 585
14.2 Enum Modifiers 586
14.3 Enum Members 586
14.4 The System.Enum Type 589
14.5 Enum Values and Operations 590
Chapter 15: Delegates 591
15.1 Delegate Declarations 592
15.2 Delegate Compatibility 595
15.3 Delegate Instantiation 595
15.4 Delegate Invocation 596
Chapter 16: Exceptions 599
16.1 Causes of Exceptions 599
16.2 The System.Exception Class 600
16.3 How Exceptions Are Handled 600
16.4 Common Exception Classes 601
Chapter 17: Attributes 603
17.1 Attribute Classes 603
17.2 Attribute Specification 607
17.3 Attribute Instances 613
17.4 Reserved Attributes 615
17.5 Attributes for Interoperation 621
Chapter 18: Unsafe Code 623
18.1 Unsafe Contexts 624
18.2 Pointer Types 627
18.3 Fixed and Moveable Variables 630
18.4 Pointer Conversions 631
18.5 Pointers in Expressions 633
18.6 The fixed Statement 640
18.7 Fixed-Size Buffers 645
18.8 Stack Allocation 648
18.9 Dynamic Memory Allocation 649
Appendix A: Documentation Comments 653
A.1 Introduction 653
A.2 Recommended Tags 655
A.3 Processing the Documentation File 666
A.4 An Example 672
Appendix B: Grammar 679
B.1 Lexical Grammar 679
B.2 Syntactic Grammar 689
B.3 Grammar Extensions for Unsafe Code 720
Appendix C: References 725
Index 727