Compiler Error CS0417

“identifier”:创建变量类型的实例时无法提供参数

如果对类型参数上的 new的调用带有参数,则会发生此错误。通过在未知参数类型上的使用new,可以被调用的唯一构造函数是不带参数的。如果需要调用另一个构造函数,请考虑使用类类型约束或接口约束。

下面的示例生成 CS0417:

// CS0417
class ExampleClass<T> where T : new()
{
    // The following line causes CS0417.
    T instance1 = new T(1);   

    // The following line doesn't cause the error.
    T instance2 = new T();
}

请参阅

类型参数的约束(C# 编程指南)