c# - type arguments can't be inferred from the usage for higher-order function -
i have following higher-order function:
public static func<t, bool> not<t>(func<t, bool> otherfunc) { return arg => !otherfunc(arg); }
and trying call that:
var isvalidstr = linqutils.not(string.isnullorwhitespace);
compiler gives me "type arguments cannot inferred usage" error. following works:
var isvalidstr = linqutils.not((string s) => string.isnullorwhitespace(s));
i wonder difference is? string.isnullorwhitespace
non-overloaded function same signature.
as mentioned in comments, following works , still doesn't explain why type inference fails in case:
var isvalidstr = linqutils.not<string>(string.isnullorwhitespace);
the details of issue dealing answered eric lippert on blog, here.
basically, "david b" said in comments, "isnullorwhitespace method group. method group has 1 participating member today, more in future."
Comments
Post a Comment