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