BACK TO BASICS

Covariance and Contravariance in .NET C#

Have hard time understanding it? Let me simplify it for you.

Ahmed Tarek
Published in
8 min readOct 26, 2021

--

Simple explanation of DotNet (.NET) CSharp (C#) Invariance, Covariance, Contravariance Cheat Sheet. Best Practice Code Coding Programming Software Development Architecture Engineering
Photo by Christina@wocintechchat.com on Unsplash

If it is so hard on you to understand what Covariance and Contravariance in .NET C# means, don’t feel ashamed of it, you are not alone.

It happened to me and many other developers. I even know experienced developers who either don’t know about them and are using them but still can’t understand them well enough.

From where I see it, this is happening because every time I come across an article talking about Covariance and Contravariance, I find it focused on some technical terminologies rather than being concerned about the reason why we have them in the first place and what we would have missed if they didn’t exist.

Simple explanation of DotNet (.NET) CSharp (C#) Invariance, Covariance, Contravariance Cheat Sheet. Best Practice Code Coding Programming Software Development Architecture Engineering
Photo by Olga Thelavart on Unsplash, modified by Ahmed Tarek

2021–11–04

I noticed that understanding Invariance, Covariance and…

--

--

Software Engineer 👨‍💻 | .NET dotnet C# csharp c-sharp | Website: https://www.developmentsimplyput.com | LinkedIn: @atarekhasan