Variance C# with Example
Generic interfaces and delegates can have their type parameters marked as covariant or contravariant using the out
and in keywords respectively. These declarations are then respected for type conversions, both implicit and
explicit, and both compile time and run time.
For example, the existing interface IEnumerable has been redeﬁned as being covariant:
The existing interface IComparer has been redeﬁned as being contravariant:
public interface IComparer
int Compare(T x, T y);