现在的位置: 首页 > 综合 > 正文

逆变,协变

2012年08月13日 ⁄ 综合 ⁄ 共 336字 ⁄ 字号 评论关闭
 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();
}
}

抱歉!评论已关闭.