0

I'd like to implement Action as func and get the error : could not use void in this context. Please advise

Action<string> someFunc_1 = Console.WriteLine;
someFunc_1("Test");

Func<string, void> someFunc_2 = Console.WriteLine;
4

2 回答 2

2

Action<T1, T2, ...>完成替换Func<T1, T2, ..., void>

你不能void在泛型中使用。它不是 C# 中的类型。

然后在你的情况下,使用Action<string>而不是Func<string, void>.

于 2013-01-31T15:31:10.913 回答
0
Func<string, bool> someFunc_2 = s =>
{
  Console.WriteLine(s);
  return true;
};
于 2013-01-31T15:30:56.440 回答