Register to Better Coder! It's free.
Enjoy the premium features and succeed at every job interview.

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/

Comments

No Comments Yet.
Be the first to tell us what you think.
.NET challenge
.NET challenge

Are you learning C# ? Try our test we designed to help you progress faster.

Test yourself

Chat

Oh, the operator is not available. Leave us your comments. We will answer all your questions as soon as possible.

Comments

LaceJaguar65
e
LaceJaguar65
e
LaceJaguar65
e
LaceJaguar65
e
LaceJaguar65
e
LaceJaguar65
e
LaceJaguar65
e
LaceJaguar65
e
LaceJaguar65
e
LaceJaguar65
e
LaceJaguar65
e
LaceJaguar65
e
LaceJaguar65
e
LaceJaguar65
e
LaceJaguar65
e
LaceJaguar65
e
LaceJaguar65
e
LaceJaguar65
e
LaceJaguar65
e
LaceJaguar65
e
LaceJaguar65
e
LaceJaguar65
e
LaceJaguar65
e
LaceJaguar65
e
LaceJaguar65
e