逆变,协变

 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();
}
}
posted @ 2011-12-14 15:22  Rookier  阅读(351)  评论(1编辑  收藏  举报