Part 2. C#2: solving the issues of C#1

In part 1 we took a quick look at a few of the features of C# 2. Now it’s time to do the job properly. We’ll see how C# 2 fixes various problems that developers ran into when using C# 1, and how C# 2 makes existing features more useful by streamlining them. This is no mean feat, and life with C# 2 is much more pleasant than with C# 1.

The new features in C# 2 have a certain amount of independence. That’s not to say they’re not related at all, of course; many of the features are based on—or at least interact with—the massive contribution that generics make to the language. However, the different topics we’ll look at in the next five chapters don’t combine into one cohesive whole.

The first four chapters of this part cover the biggest new features. We’ll look at the following:

  • Generics—. The most important new feature in C# 2 (and indeed in the CLR for .NET 2.0), generics allow type and method parameterization.

  • Nullable types—. Value types such as int and DateTime don’t have any concept of “no value present”—nullable types allow you to represent the absence of a meaningful value.

  • Delegates—. Although delegates haven’t changed at the CLR level, C# 2 makes them a lot easier to work with. As well as a few simple shortcuts, the introduction of anonymous methods begins the movement toward a more functional style of programming—this trend continues in C# 3.

  • Iterators—. While using iterators has always been simple in C# with the foreach statement, it’s a pain to implement them in C# 1. The C# 2 compiler is happy to build a state machine for you behind the scenes, hiding a lot of the complexity involved.

Having covered the major, complex new features of C# 2 with a chapter dedicated to each one, chapter 7 rounds off our coverage by covering several simpler features. Simpler doesn’t necessarily mean less useful, of course: partial types in particular are very important for better designer support in Visual Studio 2005.

As you can see, there’s a lot to cover. Take a deep breath, and let’s dive into the world of generics...

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

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