Summary
Generics brought a great addition to the CLR’s type system, allowing for improved compile-time type checking and for easier creation of highly reusable code. The core idea is to parameterize types such as interfaces, classes, structs, and delegates (as well as individual methods) on type parameters. As a result, the generically written code is applicable regardless of the types supplied for the parameters.
In this chapter, we discussed how generics are exposed in the C# programming language. First, we familiarized ourselves with the syntax used for generics at the declaration and use sites for classes and methods. Next, we learned about the (limited set of) constraint mechanisms available for generic type parameters. Finally, we discussed ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access