The C# Programming Language (Covering C# 4.0) / Edition 4

Hardcover (Print)
Used and New from Other Sellers
Used and New from Other Sellers
from $15.87
Usually ships in 1-2 business days
(Save 68%)
Other sellers (Hardcover)
  • All (9) from $15.87   
  • New (7) from $28.06   
  • Used (2) from $15.77   


“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++. Updated to cover the new features of C# 4.0, including dynamic binding, named and optional parameters, and covariant and contravariant generic types, this release takes the language to the next level by adding the ability to cleanly write programs that don’t rely on static type definitions. This allows dynamic programming languages such as Python, Ruby, and JavaScript to feel native to C#. The C# Programming Language, Fourth Edition, continues to be the authoritative and annotated technical reference for C# 4.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 for C# 4.0. The book provides the complete specification of the language, along with descriptions, reference materials, code samples, and annotations from twelve prominent C# gurus.

The many annotations 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#. With annotations from: Brad Abrams, Joseph Albahari, Krzysztof Cwalina, Jesse Liberty, Eric Lippert, Christian Nagel, Vladimir Reshetnikov, Marek Safar, Chris Sells, Peter Sestoft, Jon Skeet, and Bill Wagner.

Read More Show Less

Product Details

  • ISBN-13: 9780321741769
  • Publisher: Addison-Wesley
  • Publication date: 11/12/2010
  • Series: Microsoft .NET Development Series
  • Edition description: Annotated
  • Edition number: 4
  • Pages: 844
  • Sales rank: 433,668
  • Product dimensions: 7.50 (w) x 9.20 (h) x 1.90 (d)

Meet the Author

Anders Hejlsberg is a programming legend. He is the architect of the C# language and a Microsoft Technical Fellow. He joined Microsoft Corporation in 1996, following a thirteen-year career at Borland, where he was the chief architect of Delphi and Turbo Pascal.

Mads Torgersen is the Program Manager for the C# language at Microsoft, where he runs the day-to-day language design process and maintains the language specification.

Scott Wiltamuth is Director of Program Management for the Visual Studio Professional team at Microsoft Corporation. At Microsoft, he has worked on a wide range of development tools, including OLE Automation, Visual Basic, Visual Basic for Applications, VBScript, JScript, Visual J++, and Visual C#.

Peter Golde was the lead developer of the original Microsoft C# compiler. As the primary Microsoft representative on the ECMA committee that standardized C#, he led the implementation of the compiler and worked on the language design. He is currently an architect at Microsoft working on compilers.

Read More Show Less

Table of Contents

Foreword xi

Preface xiii

About the Authors xv

About the Annotators xvii

Chapter 1: Introduction 1

1.1 Hello, World 3

1.2 Program Structure 4

1.3 Types and Variables 6

1.4 Expressions 13

1.5 Statements 16

1.6 Classes and Objects 21

1.7 Structs 50

1.8 Arrays 53

1.9 Interfaces 56

1.10 Enums 58

1.11 Delegates 60

1.12 Attributes 61

Chapter 2: Lexical Structure 65

2.1 Programs 65

2.2 Grammars 65

2.3 Lexical Analysis 67

2.4 Tokens 71

2.5 Preprocessing Directives 85

Chapter 3: Basic Concepts 99

3.1 Application Start-up 99

3.2 Application Termination 100

3.3 Declarations 101

3.4 Members 105

3.5 Member Access 107

3.6 Signatures and Overloading 117

3.7 Scopes 120

3.8 Namespace and Type Names 127

3.9 Automatic Memory Management 132

3.10 Execution Order 137

Chapter 4: Types 139

4.1 Value Types 140

4.2 Reference Types 152

4.3 Boxing and Unboxing 155

4.4 Constructed Types 160

4.5 Type Parameters 164

4.6 Expression Tree Types 165

4.7 The dynamic Type 166

Chapter 5: Variables 169

5.1 Variable Categories 169

5.2 Default Values 175

5.3 Definite Assignment 176

5.4 Variable References 192

5.5 Atomicity of Variable References 193

Chapter 6: Conversions 195

6.1 Implicit Conversions 196

6.2 Explicit Conversions 204

6.3 Standard Conversions 213

6.4 User-Defined Conversions 214

6.5 Anonymous Function Conversions 219

6.6 Method Group Conversions 226

Chapter 7: Expressions 231

7.1 Expression Classifications 231

7.2 Static and Dynamic Binding 234

7.3 Operators 238

7.4 Member Lookup 247

7.5 Function Members 250

7.6 Primary Expressions 278

7.7 Unary Operators 326

7.8 Arithmetic Operators 331

7.9 Shift Operators 343

7.10 Relational and Type-Testing Operators 344

7.11 Logical Operators 355

7.12 Conditional Logical Operators 358

7.13 The Null Coalescing Operator 360

7.14 Conditional Operator 361

7.15 Anonymous Function Expressions 364

7.16 Query Expressions 373

7.17 Assignment Operators 389

7.18 Expression 395

7.19 Constant Expressions 395

7.20 Boolean Expressions 397

Chapter 8: Statements 399

8.1 End Points and Reachability 400

8.2 Blocks 402

8.3 The Empty Statement 404

8.4 Labeled Statements 406

8.5 Declaration Statements 407

8.6 Expression Statements 412

8.7 Selection Statements 413

8.8 Iteration Statements 420

8.9 Jump Statements 429

8.10 The try Statement 438

8.11 The checked and unchecked Statements 443

8.12 The lock Statement 443

8.13 The using Statement 445

8.14 The yield Statement 449

Chapter 9: Namespaces 453

9.1 Compilation Units 453

9.2 Namespace Declarations 454

9.3 Extern Aliases 456

9.4 Using Directives 457

9.5 Namespace Members 463

9.6 Type Declarations 464

9.7 Namespace Alias Qualifiers 464

Chapter 10: Classes 467

10.1 Class Declarations 467

10.2 Partial Types 481

10.3 Class Members 490

10.4 Constants 506

10.5 Fields 509

10.6 Methods 520

10.7 Properties 545

10.8 Events 559

10.9 Indexers 566

10.10 Operators 571

10.11 Instance Constructors 579

10.12 Static Constructors 586

10.13 Destructors 589

10.14 Iterators 592

Chapter 11: Structs 607

11.1 Struct Declarations 608

11.2 Struct Members 609

11.3 Class and Struct Differences 610

11.4 Struct Examples 619

Chapter 12: Arrays 625

12.1 Array Types 625

12.2 Array Creation 628

12.3 Array Element Access 628

12.4 Array Members 628

12.5 Array Covariance 629

12.6 Array Initializers 630

Chapter 13: Interfaces 633

13.1 Interface Declarations 633

13.2 Interface Members 639

13.3 Fully Qualified Interface Member Names 645

13.4 Interface Implementations 645

Chapter 14: Enums 663

14.1 Enum Declarations 663

14.2 Enum Modifiers 664

14.3 Enum Members 665

14.4 The System.Enum Type 668

14.5 Enum Values and Operations 668

Chapter 15: Delegates 671

15.1 Delegate Declarations 672

15.2 Delegate Compatibility 676

15.3 Delegate Instantiation 676

15.4 Delegate Invocation 677

Chapter 16: Exceptions 681

16.1 Causes of Exceptions 683

16.2 The System.Exception Class 683

16.3 How Exceptions Are Handled 684

16.4 Common Exception Classes 685

Chapter 17: Attributes 687

17.1 Attribute Classes 688

17.2 Attribute Specification 692

17.3 Attribute Instances 698

17.4 Reserved Attributes 699

17.5 Attributes for Interoperation 707

Chapter 18: Unsafe Code 709

18.1 Unsafe Contexts 710

18.2 Pointer Types 713

18.3 Fixed and Moveable Variables 716

18.4 Pointer Conversions 717

18.5 Pointers in Expressions 720

18.6 The fixed Statement 728

18.7 Fixed-Size Buffers 733

18.8 Stack Allocation 736

18.9 Dynamic Memory Allocation 738

Appendix A: Documentation Comments 741

A.1 Introduction 741

A.2 Recommended Tags 743

A.3 Processing the Documentation File 754

A.4 An Example 760

Appendix B: Grammar 767

B.1 Lexical Grammar 767

B.2 Syntactic Grammar 777

B.3 Grammar Extensions for Unsafe Code 809

Appendix C: References 813

Index 815

Read More Show Less

Customer Reviews

Average Rating 4.5
( 5 )
Rating Distribution

5 Star


4 Star


3 Star


2 Star


1 Star


Your Rating:

Your Name: Create a Pen Name or

Barnes & Review Rules

Our reader reviews allow you to share your comments on titles you liked, or didn't, with others. By submitting an online review, you are representing to Barnes & that all information contained in your review is original and accurate in all respects, and that the submission of such content by you and the posting of such content by Barnes & does not and will not violate the rights of any third party. Please follow the rules below to help ensure that your review can be posted.

Reviews by Our Customers Under the Age of 13

We highly value and respect everyone's opinion concerning the titles we offer. However, we cannot allow persons under the age of 13 to have accounts at or to post customer reviews. Please see our Terms of Use for more details.

What to exclude from your review:

Please do not write about reviews, commentary, or information posted on the product page. If you see any errors in the information on the product page, please send us an email.

Reviews should not contain any of the following:

  • - HTML tags, profanity, obscenities, vulgarities, or comments that defame anyone
  • - Time-sensitive information such as tour dates, signings, lectures, etc.
  • - Single-word reviews. Other people will read your review to discover why you liked or didn't like the title. Be descriptive.
  • - Comments focusing on the author or that may ruin the ending for others
  • - Phone numbers, addresses, URLs
  • - Pricing and availability information or alternative ordering information
  • - Advertisements or commercial solicitation


  • - By submitting a review, you grant to Barnes & and its sublicensees the royalty-free, perpetual, irrevocable right and license to use the review in accordance with the Barnes & Terms of Use.
  • - Barnes & reserves the right not to post any review -- particularly those that do not follow the terms and conditions of these Rules. Barnes & also reserves the right to remove any review at any time without notice.
  • - See Terms of Use for other conditions and disclaimers.
Search for Products You'd Like to Recommend

Recommend other products that relate to your review. Just search for them below and share!

Create a Pen Name

Your Pen Name is your unique identity on It will appear on the reviews you write and other website activities. Your Pen Name cannot be edited, changed or deleted once submitted.

Your Pen Name can be any combination of alphanumeric characters (plus - and _), and must be at least two characters long.

Continue Anonymously
Sort by: Showing all of 5 Customer Reviews
  • Anonymous

    Posted April 24, 2007

    The Definitive Reference

    The lineage is certainly there, but the ponderous accuracy of Niklaus Wirth is definitely not enlivened with the frenetic sparkle of Philippe Kahn. The authors are closer to Kahn and not academics like Wirth, but this is heavy reading. As it no doubt should be, it is the detailed description of a computer language based on a rich, experienced and proven provenance, from PL/0 to Pascal through Delphi and, arguably, beyond Java. It is a language used to describe the construction of the components, controls and objects and such that together constitute a large portion of Microsoft¿s .NET product suite, but not a description or outline of those things themselves. Most of the book (roughly the first 80%) is about C# Version 1.0, with the remainder extensions that Version 2.0, followed by even more exact appendices and, finally, a reasonably useful index. Each of the 23 chapters are broad containers for related topics, and most can be read and studied by themselves without reference to prior sections. Like most, perhaps all, computer languages, the material and its presentation has more in common with a mathematics textbook than with technical literature, but it does have a large number of simple examples that illuminate various aspects or nuances of the complex interactions and dependencies that languages have. Again, it is a reference book, and as such anyone who develops programs in C# should have it in their library.

    Was this review helpful? Yes  No   Report this review
  • Anonymous

    Posted June 14, 2006

    use Generics

    [This is a review of the SECOND EDITION, which was published in 2006. Many of the other, earlier reviews are about the First Edition.] There are many computer programming books, but only a handful of languages in widespread use. One way to choose which books to read is to look for the intersection between these 2 ideas. Namely, books written [or co-authored] by the authors of a language. Think Kernighan and Ritchie for C, Jensen and Wirth for Pascal. Well, for C#, we have this book, co-authored by C#'s architect, Hejlsberg. The book itself is probably not best for a complete newcomer to C#, who has no background in other languages. There are no easy to learn tutorial-type lessons. The authors plunge straight into the language. It might be good if you already know the basics of C#. Then this book can be used as an [the?] authoritative reference when you have questions, or if there are ambiguities in other texts. The book does show that C# is inherently easy to use. Its syntax is on a par with Java. Generally, clearer than C++, from which many readers might hail. In various newsgroups and blogs, there are ongoing arguments about the relative merits of C# and Java. Yet this book might show to many readers that the 2 languages are broadly equivalent in ease of use and functionality. (Leaving aside issues of what platforms you can run a language on.) One thing that will strike some readers is that no graphics are covered. The core C# classes described in the book are inherently those for pure computation. In this sense, the style of the book harks back to traditional texts on C and C++. Experienced programmers won't have a problem with this. But one can readily imagine new programmers, who have always used widgets, experiencing an impedance mismatch. C# does of course have graphics, using its Graphics class and System.Drawing, but the authors have chosen to exclude those from the current discussion. Also, what distinguishes this book from its first edition is the coverage of C# 2.0. Seven chapters are devoted to 2.0. I'm not going to tediously enumerate all the differences from 1.0. But perhaps the biggest improvement in 2.0 is the use of Generics. (By the way, this follows in the footsteps of Java 1.5, whose Generics have roughly the same functionality.) Whenever possible, you should use Generics. They let you parameterise the arguments of class methods and interfaces. So that some automated code checking can be moved from run time to compile time. Worth its weight in gold. Run time bug detection is expensive, especially if it's in code that is already at a customer site. Compile time checking occurs much earlier, and is essentially free by comparison.

    Was this review helpful? Yes  No   Report this review
  • Anonymous

    Posted January 27, 2004

    A great reference...

    This book is a great reference for the C# programming language as it will be in it's second incarnation (as of this time, the next version of C# has not been released). However, it is a copy of the C# lanaguage specification that can be found online at Microsoft's website, as well as is distributed with the .NET framework. However, as far as the specification is concerned, it is very good for those that want the final word on all things concerning C#. There is no guesswork here. Specifically, I would recommend this book for those that prefer to have a hard copy of the specification by their side, as well as those that want to get a better grip on aspects of the language and syntax.

    Was this review helpful? Yes  No   Report this review
  • Anonymous

    Posted November 22, 2003

    May yet be a Classic

    C# has now been publicly released by Microsoft for well over a year. In fact, it is maturing into a major upgrade, to version 2. Not surprisingly, there have been several books out on version 1. This book describes version 1 and some aspects of version 2 though these are not strictly official yet. So is that the main point of this book; to give up a heads-up on V2? Because otherwise, do we really need another book on V1? What is the point? Well, perhaps the point is that one of the authors is Hejlsberg, the architect of C#. At Borland, he was the chief architect of Delphi and Turbo Pascal. A towering figure. The blurb on the book's back cover calls him a 'programming legend'. I do not think this is hype. This book has promise of being a landmark. One of those that is forever definitively associated with a computer language. Like 'Pascal - User Manual and Report' by Jensen and Wirth, and 'The C Programming Language' by Kernighan and Ritchie. The main question about this book is the timing of its publication. It is late. Its chances of being considered in the august ranks of the above classics would have been much enhanced if it could have been published coincident with the release of C#. Sure, it would not then mention the V2 features. But that could have been put in the second version of this book. By being late, it let other explanatory texts grab that initial mindshare. Someone, NOT necessarily Hejlsberg, fumbled the ball on this one. Not too late though. The book starts a lap behind. But it may yet achieve classic status. By the way, those of you interested in the history of programming may appreciate this. Hejlsberg is the architect of C#. He is not the (only) author of C#. A team of authors at Microsoft worked on it, simply because these days a new language needs much more effort. Jensen and Wirth were the sole authors of the initial Pascal. Likewise for Kernighan and Ritchie. The simplest reason for the increased complexity is of course the GUI, which was nonexistent then. But another is that C# (and Java) use an automatic garbage collector. In C and Pascal, the programmer must explicitly dellocate, which means that the latter is a simple deterministic method. The complexity is in your wetware. Moving to an automatic GC vastly increases the language's internal complexity.

    Was this review helpful? Yes  No   Report this review
  • Anonymous

    Posted December 10, 2003

    C# Language Specification (v2.0) in print

    This is a good book, but it is not a language tutorial and is not appropriate for beginners. It is mainly a hardcopy version of the C# Language Specification. It has extensive coverage of the entire language, including the new C# 2.0 features (generics, iterators, etc.). Every C# programmer should have a copy of the language specification by their side. If you like hardcopy then buy this book. If you prefer electronic documentation you can read the specification from within Visual Studio.NET or download a copy for no cost from Microsoft.

    Was this review helpful? Yes  No   Report this review
Sort by: Showing all of 5 Customer Reviews

If you find inappropriate content, please report it to Barnes & Noble
Why is this product inappropriate?
Comments (optional)