Examples from Chapter 4 (Generics) of Programming C# 8.0 (O'Reilly).
- Example 1. Defining a generic class
- Example 2. Using a generic class
- Example 3. Constructed generic types as type arguments
- Example 4. Creating a new instance of a parameterized type
- Example 5. Using a type constraint
- Example 6. Will not compile: interface not implemented
- Example 7. Will not compile: missing constraint
- Example 8. Constraining one argument to derive from another
- Example 9. Constraint requiring a reference type
- Example 10. Constrained by another constraint
- Example 11. Constraint requiring a value type
- Example 12. Constraints requiring delegate and enum types
- Example 13. Multiple constraints
- Example 14. Getting the default (zero-like) value of a type argument
- Example 15. Getting the default (zero-like) value of an inferred type
- Example 16. A generic method
- Example 17. Invoking a generic method
- Example 18. A generic method with a constraint
- Example 19. Generic method type argument inference