如果有以下类:
class A
{
public A(int number)
{
}
}
那为什么我不能有一个像这样的通用类:
class B<ParameterClass> where ParameterClass : A
{
public B()
{
ParameterClass a = new ParameterClass(1);
}
}
我得到一个 CS0304 并且编译器说我没有 new() 限制,但我只想调用在 A 上定义的构造函数,因为 ParameterClass 将始终是 A 编译器可以确定 A(int number)构造函数将始终存在。我只是不明白为什么会有这个限制。