Part 3. C# 3—revolutionizing how we code

There is no doubt that C#2 is a significant improvement over C#1. The benefits of generics in particular are fundamental to other changes, not just in C# 2 but also in C# 3. However, C# 2 was in some sense a piecemeal collection of features. Don’t get me wrong: they fit together nicely enough, but they address a set of individual issues. That was appropriate at that stage of C#’s development, but C#3 is different.

Almost every feature in C# 3 enables one very specific technology: LINQ. Many of the features are useful outside this context, and you certainly shouldn’t confine yourself to only using them when you happen to be writing a query expression, for example—but it would be equally silly not to recognise the complete picture created by the set of jigsaw puzzle pieces presented in the remaining chapters.

I’m writing this before C#3 and .NET 3.5 have been fully released, but I’d like to make a prediction: in a few years, we’ll be collectively kicking ourselves for not using LINQ in a more widespread fashion in the early days of C# 3. The buzz around LINQ—both within the community and in the messages from Microsoft—has been largely around database access and LINQ to SQL. Now databases are certainly important—but we manipulate data all the time, not just from databases but in memory, and from files, network resources, and other places. Why shouldn’t other data sources get just as much benefit from LINQ as databases?

They do, of course—and that’s the hidden jewel of LINQ. It’s been in broad daylight, in public view—just not talked about very much. Even if you don’t talk about it, I’d like you to keep it in the back of your mind while you read about the features of C# 3. Look at your existing code in the light of the possibilities that LINQ has to offer. It’s not suitable for all tasks, but where it is appropriate it can make a spectacular difference.

It’s only been in the course of writing this book that I’ve become thoroughly convinced of the elegance and beauty of LINQ. The deeper you study the language, the more clearly you see the harmony between the various elements that have been introduced. Hopefully this will become apparent in the remainder of the book, but you’re more likely to feel it gradually as you begin to see LINQ improving your own code. I don’t wish to sound like a mindless and noncritical C# devotee, but I feel there’s something special in C#3.

With that brief burst of abstract admiration out of the way, let’s start looking at C#3 in a more concrete manner.

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

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