C# in Depth, Second Edition
Jon Skeet
  • November 2010
  • ISBN 9781935182474
  • 584 pages
  • printed in black & white
This title is out of print and no longer for sale.

The definitive what, how, and why of C#.

Eric Lippert, Microsoft

Third edition of this book is available

C# in Depth, Second Edition is a thoroughly revised, up-to-date book that covers the new features of C# 4 as well as Code Contracts. In it, you'll see the subtleties of C# programming in action, learning how to work with high-value features that you'll be glad to have in your toolkit. The book helps readers avoid hidden pitfalls of C# programming by understanding "behind the scenes" issues.

Table of Contents show full




about this book

Part 1 Preparing for the journey

1. The changing face of C# development

1.1. Starting with a simple data type

1.2. Sorting and filtering

1.3. Handling an absence of data

1.4. Introducing LINQ

1.5. COM and dynamic typing

1.6. Dissecting the .NET platform

1.7. Making your code super awesome

1.8. Summary

2. Core foundations: building on C# 1

2.1. Delegates

2.2. Type system characteristics

2.3. Value types and reference types

2.4. Beyond C# 1: new features on a solid base

2.5. Summary

Part 2 C# 2: solving the issues of C#

3. Parameterized typing with generics

3.1. Why generics are necessary

3.2. Simple generics for everyday use

3.3. Beyond the basics

3.4. Advanced generics

3.5. Limitations of generics in C# and other languages

3.6. Summary

4. Saying nothing with nullable types

4.1. What do you do when you just don’t have a value?

4.2. System.Nullableand System.Nullable

4.3. C# 2’s syntactic sugar for nullable types

4.4. Novel uses of nullable types

4.5. Summary

5. Fast-tracked delegates

5.1. Saying goodbye to awkward delegate syntax

5.2. Method group conversions

5.3. Covariance and contravariance

5.4. Inline delegate actions with anonymous methods

5.5. Capturing variables in anonymous methods

5.6. Summary

6. Implementing iterators the easy way

6.1. C# 1: the pain of handwritten iterators

6.2. C# 2: simple iterators with yield statements

6.3. Real-life iterator examples

6.4. Pseudo-synchronous code with the Concurrency and Coordination Runtime

6.5. Summary

7. Concluding C# 2: the final features

7.1. Partial types

7.2. Static classes

7.3. Separate getter/setter property access

7.4. Namespace aliases

7.5. Pragma directives

7.6. Fixed-size buffers in unsafe code

7.7. Exposing internal members to selected assemblies

7.8. Summary

Part 3 C# 3: revolutionizing how we code

8. Cutting fluff with a smart compiler

8.1. Automatically implemented properties

8.2. Implicit typing of local variables

8.3. Simplified initialization

8.4. Implicitly typed arrays

8.5. Anonymous types

8.6. Summary

9. Lambda expressions and expression trees

9.1. Lambda expressions as delegates

9.2. Simple examples using List and events

9.3. Expression trees

9.4. Changes to type inference and overload resolution

9.5. Summary

10. Extension methods

10.1. Life before extension methods

10.2. Extension method syntax

10.3. Extension methods in .NET 3.5

10.4. Usage ideas and guidelines

10.5. Summary

11. Query expressions and LINQ to Objects

11.1. Introducing LINQ

11.2. Simple beginnings: selecting elements

11.3. Filtering and ordering a sequence

11.4. Let clauses and transparent identifiers

11.5. Joins

11.6. Groupings and continuations

11.7. Choosing between query expressions and dot notation

11.8. Summary

12. LINQ beyond collections

12.1. Querying a database with LINQ to SQL

12.2. Translations using IQueryable and IQueryProvider

12.3. LINQ-friendly APIs and LINQ to XML

12.4. Replacing LINQ to Objects with Parallel LINQ

12.5. Inverting the query model with LINQ to Rx

12.6. Extending LINQ to Objects

12.7. Summary

Part 4 C# 4: playing nicely with others

13. Minor changes to simplify code

13.1. Optional parameters and named arguments

13.2. Improvements for COM interoperability

13.3. Generic variance for interfaces and delegates

13.4. Teeny tiny changes to locking and field-like events

13.5. Summary

14. Dynamic binding in a static language

14.1. What? When? Why? How?

14.2. The five-minute guide to dynamic

14.3. Examples of dynamic typing

14.4. Looking behind the scenes

14.5. Implementing dynamic behavior

14.6. Summary

15. Letting your code speak more clearly with Code Contracts

15.1. Life before Code Contracts

15.2. Introducing Code Contracts

15.3. Rewriting binaries with ccrewrite and ccrefgen

15.4. Static checking

15.5. Documenting contracts with ccdocgen

15.6. Practical contracts

15.7. Summary

16. Whither now?

16.1. C# — mixing tradition and modernity

16.2. Computer science and .NET

16.3. The world of computing

16.4. Farewell

Appendix A: LINQ standard query operators

Appendix B: Generic collections in .NET

Appendix C: Version summaries


About the Technology

C# 4 is even more expressive and powerful than earlier versions. You can do amazing things with generics, lambda expressions, dynamic typing, LINQ, iterator blocks, and other features—but you first have to learn C# in depth.

What's inside

  • New features of C# 4
  • Underused features of C#
  • Guidance and practical experience

About the reader

This book assumes its readers know the basics of C# and are ready to sink their teeth into the good stuff!

About the author

Jon Skeet is a Google software engineer working in London. A C# MVP since 2003 and prominent C# community personality, Jon's heart belongs to C#.