逆变,协变
class Fax
{
}
class LaserPrinter : Fax
{
}
delegate Tresult Func<in T,out Tresult>(T arg);//out 关键字指定该类型参数是协变的,in 关键字指定该类型参数是逆变的
class Program
{
private static T Min<T>(T o, T b)where T:class,IComparable<T>
{
Func<Fax, LaserPrinter> l = teee;
Func<LaserPrinter, Fax> f = l;//逆变
//协变
if (o.CompareTo(b) < 0) return o;
return b;
}
static LaserPrinter teee(Fax i)
{
return new LaserPrinter();
}
}