What is covariance and contravariance?
Experience Level: Senior
Tags: .NETASP.NET MVCASP.NET WebAPIASP.NET WebFormsC#
Answer
Covariance
Covariance enables you to pass a derived type where a base type is expected.
- Co-variance is like variance of the same kind.
- The base class and other derived classes are considered to be the same kind of class that adds extra functionalities to the base type. So covariance allows you to use a derived class where a base class is expected.
Hint: can accept big if small is expected.
Links
https://blogs.msdn.microsoft.com/ericlippert/tag/covariance-and-contravariance/
Related C# job interview questions
What is a namespace in C# and what is it good for?
C# JuniorWhat is abstract class and what is it good for?
C# MediorHave you ever consumed some 3rd party API? What was it? Have you ever designed your own API? Could you describe it a bit?
.NETArchitectureASP.NET WebAPIC#Web services MediorWhat is serialization/deserialization? What types of serialization do you know?
.NETC# MediorWhat is a MultiCastDelegate? What is it good for? Give some real use case
.NETC# Senior
Chat
Oh, the operator is not available. Leave us your comments. We will answer all your questions as soon as possible.
Anonymous
Καλησπέρα.
Καλησπέρα.
Anonymous
the infinteis -3/15 so 1triition / infinet
the infinteis -3/15 so 1triition / infinet
Anonymous
e
e
Anonymous
<a href="https://inspirum.pl "
<a href="https://inspirum.pl "
Anonymous
[url]https://inspirum.pl[/url]
[url]https://inspirum.pl[/url]
LaceJaguar65
e
e
LaceJaguar65
e
e
LaceJaguar65
e
e
LaceJaguar65
e
e
LaceJaguar65
e
e
LaceJaguar65
e
e
LaceJaguar65
e
e
LaceJaguar65
e
e
LaceJaguar65
e
e
LaceJaguar65
e
e
LaceJaguar65
e
e
LaceJaguar65
e
e
LaceJaguar65
e
e
LaceJaguar65
e
e
LaceJaguar65
e
e
LaceJaguar65
e
e
LaceJaguar65
e
e
LaceJaguar65
e
e
LaceJaguar65
e
e
LaceJaguar65
e
e