Difference between Covariance & Contravariance

It’s probably easiest to give examples – that’s certainly how I remember them.  (covariant return types/contravariant parameter types) Covariance Canonical examples: IEnumerable<out T>, Func<out T> You can convert from IEnumerable<string> to IEnumerable<object>, or Func<string> to Func<object>. Values only come out from these objects. It works because if you’re only taking values out of the API, and it’s going to return something specific (like string), you can…

Continue reading