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.
我在许多使用 Action 委托的在线示例中看到了这一行:
public event Action MyEvent;
但是当我在自己的代码中尝试时,我得到了这个错误
使用泛型“System.Action”需要“1”类型参数
该文档当然描述了一种没有任何类型参数的 Action 形式。我错过了什么?
扩展安德鲁斯的答案。
在非 3.5 场景中使用 Action 是完全合法的。只需自己定义即可。
public delegate void Action();
确保您的应用程序正在引用System.Core.
System.Core
编辑 - 还要确保您的目标是 .NET 3.5,因为 System.Core.dll 是该版本的一部分。