I need to understand the difference between Covariance & Contravariance with a simple example as there are many articles which only talke about covariance but not about contravariance.
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Rajesh SinghPosted Dec 27, 2015, 3:15 AM
Francis SusaimichaelPosted Oct 23, 2015, 5:30 AM
Sumit AroraPosted Oct 23, 2015, 3:51 AM
Francis SusaimichaelPosted Oct 23, 2015, 3:30 AM
Normally, the method that you pass to a delegate must have the same return type and signature as the delegate. However, covariance and contravariance relax this rule slightly, as it pertains to derived types. Covariance enables a method to be assigned to a delegate when the method’s return type is a class derived from the class specified by the return type of the delegate. Contravariance enables a method to be assigned to a delegate when a method’s parameter type is a base class of the class specified by the delegate’s declaration.
Ravi PatelPosted Oct 23, 2015, 2:57 AM