Chapter 3. C# 3: LINQ and everything that comes with it
This chapter covers
- Implementing trivial properties simply
- Initializing objects and collections more concisely
- Creating anonymous types for local data
- Using lambda expressions to build delegates and expression trees
- Expressing complex queries simply with query expressions
The new features of C# 2 were mostly independent of each other. Nullable value types depended on generics, but they were still separate features that didn’t build toward a common goal.
C# 3 was different. It consisted of many new features, each of which was useful in its own right, but almost all of which built toward the larger goal of LINQ. This chapter shows each feature individually and then demonstrates how they fit together. The first feature we’ll look at is the only one that has no direct relationship with LINQ.
Prior to C# 3, every property had to be implemented manually with bodies for the get and/or set accessors. The compiler was happy to provide an implementation for field-like events but not properties. That meant there were a lot of properties like this:
private string name; public string Name { get { return name; } set { name = value; } }