Coding Tutorial: Got your head around covariance? Here's contravariance - welcome to opposite land! Source code available at: github.com/JasperKent/Contrav...
Anything you'd like to see a video on? Do ask below. Download the source code at github.com/JasperKent/Contravariance For more videos, subscribe here: ru-vid.com/show-UCqWQzlUDdllnLmtgfSgYTCA
I now understand the difference and the hows but the deep WHY still seems to elude me. I guess because of the way things are done, it can break Liskov but wouldnt contra break liskov or is it just the locking down of the one way or another that makes us unable to break Liskov...? Also the delegates that do BOTH Co and Contra confuse me... wouldnt I be able to make something that takes say Fruit both in and out? FOR EXAMPLE: delegate Tout CanIBreakDelegate(T myIn, T myOtherIn); and then in program.cs CanIBreakDelegate canIBreak = (l, r) => new Apple(); so this works just fine but I have no idea what it means, lol...
Okay, I've had a think. The thing to remember is that co- and contravariance are about the heritability of the generic itself, no the generic parameter. Let's introduce a second level of inheritance, so Fruit
Great video, I finally think I get Contravariance in C#. Could you add links between this and your video on Covariance to both videos. Would have made this video much easier to find. Thanks