Chapter 15. Generic and Anonymous Types

In this chapter, we will look at the C# support for generic and anonymous types. Anonymous types are relatively simple, so most of this chapter is dedicated to the much more complex and involved topic of generic types.

Understanding generic types requires a good understanding of regular C# types, so if you have skipped over the chapters before this one, I suggest you go back and read more closely. Chapters 1, 3, and 9 have particular bearing on this chapter, which is summarized in Table 15-1.

Table 15-1. Quick Problem/Solution Reference for Chapter 15

Problem

Solution

Listings

Create a class, struct, or interface that works with a type that is selected at instantiation.

Create and instantiate a generic class, struct, ...

Get Introducing Visual C# 2010 now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.