Code inspection: Redundant type arguments of method
Last modified: 05 June 2024tip
This inspection reports redundant type arguments on calls of generic methods, where the compiler can automatically infer the type.
Consider this example:
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.