【发布时间】:2013-07-13 01:05:21
【问题描述】:
我很困惑。在Why are interfaces in .Net reference types? 中,据说.Net 中的接口是引用类型。 第一个代码 sn -p 无法编译。它说类似“T 必须是引用类型...”
public ISomeInterface DoMagic<T>(Expression<Func<object>> action, Tuple<string, DateTime, decimal> tuple)
where T : ISomeInterface
{
Magician m = new Magician();
return m.Magic<T>(()=> action, tuple.Item3);
}
第二个编译。
public ISomeInterface DoMagic<T>(Expression<Func<object>> action, Tuple<string, DateTime, decimal> tuple)
where T : class, ISomeInterface
{
Magician m = new Magician();
return m.Magic<T>(()=> action, tuple.Item3);
}
如果接口是引用类型,为什么第一个代码 sn-p 无法编译?
【问题讨论】:
-
值类型也可以实现接口。