这不应该是有效的C#代码吗?
class A<T> where T : class {
public void DoWork<K>() where K : T {
var b = new B<K>(); // <- compile time error
}
}
class B<U> where U : class {
}
Run Code Online (Sandbox Code Playgroud)
编译器吐出此错误:
错误CS0452:类型"K"必须是引用类型,以便在泛型类型或方法"ConsoleApplication1.B"中将其用作参数"U"
编译器是否应该能够确定K是约束为T类型还是从T派生,因此它显然应该是引用类型(T被约束为引用类型)?