visual-studio-2010 - C# 4 可选空事件处理程序

标签 visual-studio-2010 c#-4.0 parameters event-handling arguments

我正在尝试编写一个具有可选 EventHandler 参数的方法。它目前看起来像这样:

public void AddItemToMainMenu(MenuItem parentMenu, MenuItems item, String menuItemText, bool isChecked, EventHandler? eventHandler = null)

错误发生在最后一个参数上,它指出:

Error 51 The type 'System.EventHandler' must be a non-nullable value type in order to use it as parameter 'T' in the generic type or method 'System.Nullable'

编辑:我已经删除了?现在收到一个非常相似的错误,我还对另一个参数做了一个不重要的更改。现在内容如下:

 public void AddItemToMainMenu( MenuItems item, String menuItemText, bool isChecked, EventHandler eventHandler = null, MenuItem? parentMenu = null)

Error 41 The type 'System.EventHandler' must be a non-nullable value type in order to use it as parameter 'T' in the generic type or method 'System.Nullable'

最佳答案

EventHandler 是一个引用类型,因此本质上可以为空。 应该是:

public void AddItemToMainMenu(MenuItem parentMenu, MenuItems item, String menuItemText, bool isChecked, EventHandler eventHandler = null)

关于visual-studio-2010 - C# 4 可选空事件处理程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11094785/

相关文章:

python - 如何在Python中从文本文件传递输入参数?

amazon-web-services - Cloudformation - 在 EC2 服务器中使用参数

c++ - Visual Studio 2010 C++ : malloc()/HeapAlloc always allocates new page for even smallest alloc size

visual-studio-2010 - 是否可以在 Visual Studio 中为动态对象提供智能感知?

sql-server-2005 - 隐式和显式交易之间的区别

validation - 带参数的 Angular 2 自定义验证器

asp.net - 为什么程序立即启动和退出?

java - Visual Studio 代码调试器 (Java)

xml - Visual Studio 2010 : XML XSD Schema to Classes within the IDE

c# - 使用 LINQ 解析字符串中的数字