Generics
IT Notes → C# @ December 22, 2020
- Reusability with a “template” that contains “placeholder” types.
- Generic types are not covariant. This means that even if B can be cast to A, T<B> cannot be cast to T<A>.
- Three kinds of constraints are derivation constraint, constructor constraint and reference/value constraint.
- In derivation constraint base constrained must never have lower visibility than generic type parameter.
- Order: (1) reference/value constraint (2) derivation constraint (3) constructor constraint.
Subscribe
Login
0 Comments