我无法理解为什么以下代码段没有给我错误
public void SomeMethod<T>(T arg) where T : MyInterface
{
MyInterface e = arg;
}
但是这个,由于泛型类型约束,我希望它可以工作
private readonly IList<Action<MyInterface>> myActionList = new List<Action<MyInterface>>();
public IDisposable Subscribe<T>(Action<T> callback) where T: MyInterface
{
myActionList.Add(callback); // doesn't compile
return null
}
给出这个错误
cannot convert from 'System.Action<T>' to 'System.Action<MyInterface>'
我正在使用 VS2012 sp1 和 .NET 4.5。
谁能解释为什么约束不允许编译?