I have the following higher-order function:
public static Func<T, bool> Not<T>(Func<T, bool> otherFunc)
{
return arg => !otherFunc(arg);
}
And trying to call it like that:
var isValidStr = LinqUtils.Not(string.IsNullOrWhiteSpace);
Compiler gives me "type arguments cannot be inferred from the usage" error. But the following works:
var isValidStr = LinqUtils.Not((string s) => string.IsNullOrWhiteSpace(s));
I wonder what the difference is?
string.IsNullOrWhiteSpace
is already a non-overloaded function with the exactly same signature.
As mentioned in comments, the following also works and still doesn't explain why type inference fails in this case:
var isValidStr = LinqUtils.Not<string>(string.IsNullOrWhiteSpace);