KEY POINTS
- Covariance is implemented with generics.
- Out keyword has to be used
- this will not work !!
IPlay<Cricket> cricketer= new Play<ODICricket>();
- this will not work !!
namespace Covariance
{
public interface IPlay
{
void Play();
}
public class Play : IPlay
{
void IPlay.Play()
{
Console.WriteLine("Play Cricket!!");
}
}
public class Cricket
{
public virtual void Play()
{
}
}
public class ODICricket : Cricket
{
public override void Play()
{
}
}
public class T20Cricket : Cricket
{
public override void Play()
{
}
}
}
PROGRAM.CS
using Covariance;
//this will not work !!
IPlay cricketer= new Play();