Code inspection: Redundant type arguments of method
This inspection reports redundant type arguments on calls of generic methods, where the compiler can automatically infer the type.
Consider this example:
void TestMethod<T>(T argument)
{
Console.WriteLine(argument);
}
void AnotherMethod(int number)
{
// Type argument specification is redundant
TestMethod<int>(number);
}
In the AnotherMethod
, the TestMethod<int>(number)
call includes an explicit type argument specification <int>
, which is unnecessary because the .NET runtime uses type inference, and it knows that number
is an integer. Therefore <int>
can be safely removed to make the code more concise.
Last modified: 05 June 2024