Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
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;
Action<T1, T2, ...>完成替换Func<T1, T2, ..., void>。
Action<T1, T2, ...>
Func<T1, T2, ..., void>
你不能void在泛型中使用。它不是 C# 中的类型。
void
然后在你的情况下,使用Action<string>而不是Func<string, void>.
Action<string>
Func<string, void>
Func<string, bool> someFunc_2 = s => { Console.WriteLine(s); return true; };