Intermediate
C#
Q50 / 100
What is covariance and contravariance in C# generics?
Correct! Well done.
Incorrect.
The correct answer is B) Covariance (out) allows using a more derived type; contravariance (in) allows using a less derived type in generic parameter position
B
Correct Answer
Covariance (out) allows using a more derived type; contravariance (in) allows using a less derived type in generic parameter position
Explanation
IEnumerable<out T> is covariant — IEnumerable<Dog> can be assigned to IEnumerable<Animal>. IComparer<in T> is contravariant.
Progress
50/100