How to call invoke when use Func

2019-08-03 18:52发布

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

标签: c# .net lambda
2条回答
Explosion°爆炸
2楼-- · 2019-08-03 19:25
bool b = f(someString);

or:

bool b = f.Invoke(someString);
查看更多
Lonely孤独者°
3楼-- · 2019-08-03 19:31

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");
查看更多
登录 后发表回答