Compiler Error CS0411
The type arguments for method 'method' cannot be inferred from the usage. Try specifying the type arguments explicitly.
This error occurs if you call a generic method without explicitly providing the type arguments and the compiler cannot infer which type arguments are intended. To avoid this error, add the intended type arguments in angle brackets.
Example 1
The following sample generates CS0411:
// CS0411.cs
class C
{
void G<T>()
{
}
public static void Main()
{
G(); // CS0411
// Try this instead:
// G<int>();
}
}
Example 2
Other possible error cases include when the parameter is null
, which has no type information:
// CS0411b.cs
class C
{
public void F<T>(T t) where T : C
{
}
public static void Main()
{
C c = new C();
c.F(null); // CS0411
}
}
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