Chapter 3. Parameterized typing with generics

This chapter covers

  • Understanding generic types and methods
  • Type inference for generic methods
  • Type constraints
  • Reflection and generics
  • CLR behavior
  • Limitations of generics
  • Comparisons with other languages

True[1] story: The other day my wife and I did our weekly grocery shopping. Just before we left, she asked me if I had the list. I confirmed that I did have the list, and off we went. It was only when we got to the grocery store that our mistake made itself obvious. My wife had been asking about the shopping list whereas I’d actually brought the list of neat features in C# 2. When we asked an assistant whether we could buy any anonymous methods, we received a strange look.

1 By which ...

Get C# in Depth, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.