Generics can be constrained in the following ways
- Interface - Allow only types that implement the specified interface
- Base Class - Allow only types that are descendents of (or are) the specified base class
- Constructor - Allow only types that have a parameterless constructor
- Reference or value type - Allows value or reference types
Additional Resources
Constraints on Type Parameters, C# (Microsoft)
Defining and Using Generics, Visual Basic (Microsoft)
No comments:
Post a Comment