Part 2. C# 2–5

This part of the book covers all the features introduced between C# 2 (shipped with Visual Studio 2005) and C# 5 (shipped with Visual Studio 2012). This is the same set of features that took up the entire third edition of this book. Much of it feels like ancient history now; for example, we simply take it for granted that C# includes generics.

This was a tremendously productive period for C#. Some of the features I’ll cover in this part are generics, nullable value types, anonymous methods, method group conversions, iterators, partial types, static classes, automatically implemented properties, implicitly typed local variables, implicitly typed arrays, object initializers, collection initializers, anonymous types, lambda expressions, extension methods, query expressions, dynamic typing, optional parameters, named arguments, COM improvements, generic covariance and contravariance, async/await, and caller information attributes. Phew!

I expect most of you to be at least somewhat familiar with most of the features, so I ramp up pretty fast in this part. Likewise, for the sake of reasonable brevity, I haven’t gone into as much detail as I did in the third edition. The intention is to cover a variety of reader needs:

  • An introduction to features you may have missed along the way
  • A reminder of the features you once knew about but have forgotten
  • An explanation of the reasons behind the features: why they were introduced and why they were designed in the way they were
  • A quick reference in case you know what you want to do but have forgotten some syntax

If you want more detail, please refer to the third edition. As a reminder, purchase of the fourth edition entitles you to an e-book copy of the third edition.

There’s one exception to this brief coverage rule: I’ve completely rewritten the coverage of async/await, which is the largest feature in C# 5. Chapter 5 covers what you need to know to use async/await, and chapter 6 addresses how it’s implemented behind the scenes. If you’re new to async/await, you’ll almost certainly want to wait until you’ve used it a bit before you read chapter 6, and even then, you shouldn’t expect it to be a simple read. I’ve tried to explain things as accessibly as I can, but the topic is fundamentally complex. I do encourage you to try, though; understanding async/await at a deep level can help boost your confidence when using the feature, even if you never need to dive into the IL the compiler generates for your own code. The good news is that after chapter 6, you’ll find a little relief in the form of chapter 7. It’s the shortest chapter in the book and a chance to recover before exploring C# 6.

With all introductions out of the way, brace yourself for an onslaught of features.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset