How to call invoke when use Func

2019-08-03 18:58发布

问题:

In the function Test(Func<string,bool> f), how to call f.invoke()? I received the error Delegate 'Func' does not take '0' arguments

回答1:

The delegate Func<string, bool> is a delegate that takes a string as an argument and returns bool. To invoke it, you need to supply a string.

e.g., either should work

f("foo");
f.Invoke("foo");


回答2:

bool b = f(someString);

or:

bool b = f.Invoke(someString);


标签: c# .net lambda