Compiler Error CS0417
TOC
Collapse the table of content
Expand the table of content

Compiler Error CS0417

 

'identifier': cannot provide arguments when creating an instance of a variable type

This error occurs if a call to the new operator on a type parameter has arguments. The only constructor that can be called by using the new operator on an unknown parameter type is a constructor that has no arguments. If you need to call another constructor, consider using a class type constraint or interface constraint.

Example

The following example generates 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();
}

Show:
© 2016 Microsoft