I should have written this a little while ago, but it slipped my mind. Despite that, I think it’s pretty exciting for anyone who’s actually following along in the early access edition (and yes, such people do exist). The reason? These are the first C# 3 chapters. Here’s what they’ve got in them:
Chapter 8: Cutting fluff with a smart compiler
This is a bit like chapter 7, in that it’s a collection of small features. The difference between the two chapters is that the features in C# 3 mostly work together towards LINQ, so there’s more of an obvious connection between them. In this chapter we look at:
- Automatically implemented properties (a.k.a. automatic properties)
- Implicit typing of local variables (the “var” keyword – note that this is not dynamic typing)
- Simplified initialization (object initializers, collection initializers)
- Implicitly typed arrays
- Anonymous types
Chapter 9: Lambda expressions and expression trees
If you have been following C# 3, you’ll know what these topics are – and if you don’t, I certainly can’t do them justice in a short blog post. In some senses, these are actually simple concepts: an easier way of creating a delegate instance, and a way of representing code as data, optionally using the same syntax. The implications of this are massive, though. We could have LINQ without anonymous types, even though it would be more painful. With that out of the way we wouldn’t really need implicitly typed local variables or arrays. But without expression trees and lambda expressions, LINQ would be dead in the water.
It takes more than just the concepts being there in the first place though. When was the last time you looked at the rules of type inference for generic methods? If your answer is “never” then you’re probably in the company of 99% of C# developers – and that’s perfectly reasonable, to be honest. However, the rules have changed for C# 3 to make them more powerful – to let the compiler do more work for us. The last part of chapter 9 deals with the changes. I should warn you, it’s not pretty – but it’s worth knowing that the rules are explained (with a little bit of hand waving) in a format which is slightly more user friendly than the specification.
So, that’s the most recent two chapters. The next to chapters to be released actually conclude the “strictly C#” part of the book, leaving just LINQ providers and the conclusion – we’re nearly there!