Chapter 5. Generic Methods

As developers get acclimated to generics, they tend to focus their attention squarely on generic classes. And, although generic classes may represent a big part of what generics bring to the table, they only represent one facet of what can be achieved with generics. As an example, the .NET generics implementation also allows you to create individual generic methods. These methods employ the same concepts that are associated with generic classes. And, as you will see in this chapter, this ability to leverage generics at this finer level of granularity can come in quite handy. As part of looking at generic methods, this chapter covers all the basic mechanics associated with declaring and consuming a generic method. Along the way, you also see a few examples that illustrate different patterns for introducing generic methods into your existing solutions. Ultimately, you're likely to find a number of opportunities to apply generic methods to your existing applications.

Get Professional .NET 2.0 Generics 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.