Covariance and Contravariance

The Idea

Covariance: Presever assignment compatibility
Contravariance: Reverses assignment compatibility
Covariance and contravariance enable implicit reference conversion for array, delegate, and generic types.

In C# there are three areas where it plays an important role

  • Array Types
  • Generic Type Arguments

Covariance with Delegates

Contravariance with Delegates

Covariance with arrays

Covariance with Generics

Contravariance with Generics



Thanks to Greg Kalapos for his video on YouTube

I am a photographer, a runner, a cyclist, and an aspiring storyteller who happened to fall in love with coding and have the desire to be proud of what I do.