Skip to content

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.
0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x