Chapter 8. Cutting fluff with a smart compiler

 

This chapter covers

  • Automatically implemented properties
  • Implicitly typed local variables
  • Object and collection initializers
  • Implicitly typed arrays
  • Anonymous types

We’ll start looking at C# 3 in the same way that we finished looking at C# 2—with a collection of relatively simple features. These are just the first small steps on the path to LINQ. Each of them can be used outside that context, but almost all are important for simplifying code to the extent that LINQ requires in order to be effective.

One important point to note is that although two of the biggest features of C# 2—generics and nullable types—required CLR changes, there were no significant changes to the CLR that shipped with .NET 3.5. There were some tweaks, but nothing fundamental. The framework grew to support LINQ, and a few more features were introduced to the base class library, but that’s a different matter. It’s worth being clear in your mind which changes are only in the C# language, which are library changes, and which are CLR changes.

Almost all of the new features exposed in C# 3 are due to the compiler being willing to do more work for you. You saw some evidence of this in part of the book—particularly with anonymous methods and iterator blocks—and C# 3 continues in the same vein. In this chapter, you’ll meet the following features that are new to C# 3:

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

 
 
 
sitemap

Unable to load book!

The book could not be loaded.

(try again in a couple of minutes)

manning.com homepage