Since covariance and especially contravariance often give me headaches (especially with Action and Func), some links
Posted by jpluimers on 2025/02/12
For my reading list (will likely be extended in the future) as covariance and especially contravariance often give me headaches (even after all these years of C#):
- [Wayback/Archive] C# – Method returning Action from covariance – Stack Overflow (thanks [Wayback/Archive] IsakGo, [Wayback/Archive] Sweeper and [Wayback/Archive] Eric Lippert)
- [Wayback/Archive] c# – Why can’t I take a contravariant interface as a parameter to a method on the interface? – Stack Overflow (thanks [Wayback/Archive] just.another.programmer, [Wayback/Archive] Charlieface and [Wayback/Archive] Sweeper)
- [Wayback/Archive] c# – Covariance and Contravariance with Func in generics – Stack Overflow (thanks [Wayback/Archive] Robertas, [Wayback/Archive] Eric Lippert, [Wayback/Archive] Peter Duniho and [Wayback/Archive] John Wu)
- [Wayback/Archive] c# – Contravariance invalid when using interface’s delegate as a parameter type – Stack Overflow (thanks [Wayback/Archive] V0ldek and [Wayback/Archive] Charlieface)
The “flipping” on each indirection level mentioned in the first two StackOverflow questions is one of the hardest parts for my mind to get right.
Oh, I totally missed that Eric Lippert has moved to Meta Platforms almost 10 years ago but he is: [Wayback/Archive] About Eric Lippert | Fabulous adventures in coding.
--jeroen






Leave a comment