While hanging at the pool last night with the kids, I finished an excellent book on C# by Jon Skeet, called C# in Depth: What you need to master C# 2 and 3. The book is about 370 pages, but feels like twice that size base on the depth of its content. Jon not only shows you what is possible with all the new language features in C# 2 and 3, but also explains why they are possible, the problems they solve in previous versions of the language, and thoughts on when and how to use them. By combining both the C# 2 and C# 3 languages features in a single book with an emphasis on the evolution of the language, you end up with a clear roadmap of C# and an appreciation and deeper understanding as to why you are using certain features as you develop.
In my opinion, it was enjoyable to read the C# 2 coverage in the book as much as it was to read the C# 3 coverage. If you feel you could use a better understanding of delegates, generics, nullable types, anonymous methods, and iterators, Jon goes into it pretty deep. Along the way he is going to challenge a lot of myths, explain a number of concepts like covariance and contravariance, show a lot more type inference occurring than I originally thought was possible, and provide numerous code snippets that will give you a better command of using those features to their fullest. During his trip into C# 2, he provides you with a look back at C# 1 so you understand the evolution that is occuring as well as giving you sneak peeks at C# 3 when appropriate.
One of the big values to note is that Jon is mainly focusing on the C# language and at times showing the framework taking advantage of those features. This gives you an appreciation for both the C# language and the .NET Framework and a clear understanding of both.
Jon then dives into the what, how, and why of the C# 3 features ( and compiler features ): automatically implemented properties, implicitly typed local variables, object and collection intializers, implicitly typed arrays, anonymous types, lambda expressions, expression trees, extension methods, etc. While discussing these features, we always get the reasons behind the new features in terms of the previous versions of the C# language. What was nice here is that we weren’t getting pounded with LINQ when talking about C# 3. We get plenty of that from a LINQ book and it was nice to stay focused on the C# 3 language itself. I particularly enjoyed the topics of lambda expressions and expression trees as they are a probably a bit more difficult to digest of all the new features. I also love the whole evolution of delegates as we move from anonymous methods to lambda expressions. I can never read too much of that We also get a nice combination of code samples mixing C# 2 and C# 3 features in numerous ways to show off the possibilities.
Last, C# In Depth gives you a quick introduction of LINQ and its flavors of LINQ To Objects, LINQ To Datasets, and LINQ To SQL. This isn’t a LINQ book, so you’re not getting in-depth coverage in these areas, but rather just an introduction to give you a taste for applying the C# features covered as they pertain to LINQ. Think of the coverage as a transition to a book on LINQ.
Overall, I cannot think of anything I would really change about the book. The coverage was solid. I will say it is a challenging read, so don’t think you are going to breeze right through it. I ended up reading several sections over and over and often had Snippet Compiler running on the laptop to run the code snippets. Because the book is frequently looking back to previous versions of C# or looking ahead when appropriate to give you the full picture, you need to stay on your toes. It is all worth it in the end, however
I highly recommend C# in Depth for anyone wanting a better grasp of the C# language.
by David Hayden