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();
}
See also
Collaborate with us on GitHub
The source for this content can be found on GitHub, where you can also create and review issues and pull requests. For more information, see our contributor guide.
Feedback
https://aka.ms/ContentUserFeedback.
Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see:Submit and view feedback for