With regard to the following extension methods:
public static class Extensions
{
public static void P<T>(this T value) { }
public static TResult F<T, TResult>(this T value)
{
return default(TResult);
}
}
When I try to use these with various type parameter options, I get the following results:
1.P(); // Compiler just fine
1.P<int>(); // R# says "Type argument specification is redundant"
var x = 1.F<int, int>(); // Compiler just fine
var y = 1.F<int>(); // Compiler error: Incorrect number of type parameters
So how come the compiler can infer the type of T
for P
, yet cannot infer the same for F
? What are the rules around such inference and is there a way I can avoid the need to specify the types like this?