Chapter 2. C# 2

 

This chapter covers

  • Using generic types and methods for flexible, safe code
  • Expressing the absence of information with nullable value types
  • Constructing delegates relatively easily
  • Implementing iterators without writing boilerplate code

If your experience with C# goes far enough back, this chapter will be a reminder of just how far we’ve come and a prompt to be grateful for a dedicated and smart language design team. If you’ve never programmed C# without generics, you may end up wondering how C# ever took off without these features.[1] Either way, you may still find features you weren’t aware of or details you’ve never considered listed here.

1 For me, the answer to this one is simple: C# 1 was a more productive language for many developers than Java was at the time.

It’s been more than 10 years since C# 2 was released (with Visual Studio 2005), so it can be hard to get excited about features in the rearview mirror. You shouldn’t underestimate how important its release was at the time. It was also painful: the upgrade from C# 1 and .NET 1.x to C# 2 and .NET 2.0 took a long time to roll through the industry. Subsequent evolutions have been much quicker. The first feature from C# 2 is the one almost all developers consider to be the most important: generics.

2.1. Generics

2.2. Nullable value types

2.3. Simplified delegate creation

2.4. Iterators

2.5. Minor features

Summary

sitemap