AlgoMaster Logo

Covariance & Contravariance

Last Updated: May 22, 2026

Medium Priority
17 min read

Variance is the set of rules that decide when one generic type is assignable to another. Specifically, when Product inherits from Item, is IEnumerable<Product> also an IEnumerable<Item>? The short answer is "sometimes, and only if you ask for it explicitly with out or in." This chapter walks through why the default answer is "no," when the compiler will say "yes," and how the out and in keywords give you control over the trade-off.

Premium Content

Subscribe to unlock full access to this content and more premium articles.