我有些困惑。在Why are interfaces in .Net reference types?中提到,.NET中的接口是引用类型。
第一段代码无法编译。它会显示类似于"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);
}
如果接口是引用类型,为什么第一个代码片段无法编译?