Skip to main content

Explain covariance and contravariance in delegates and generics in detail.

Expert C#
Quick Answer Covariance (out T) on interfaces like IEnumerable means IEnumerable is assignable to IEnumerable. Contravariance (in T) on delegates like Action means Action is assignable to Action. These only apply to interfaces and delegates รขโ‚ฌโ€ not concrete generic classes.

Answer

out = covariance, in = contravariance.

Allows safe substitutability. Includes delegate variance, IEnumerable variance, and array pitfalls.

S
SugharaIQ Editorial Team Verified Answer

This answer has been peer-reviewed by industry experts holding senior engineering roles to ensure technical accuracy and relevance for modern interview standards.

Want to bookmark, take notes, or join discussions?

Sign in to access all features and personalize your learning experience.

Sign In Create Account

Source: SugharaIQ

Ready to level up? Start Practice