I am attempting to write a method that has an optional EventHandler Paramater. it currently looks like this:
public void AddItemToMainMenu(MenuItem parentMenu, MenuItems item, String menuItemText, bool isChecked, EventHandler? eventHandler = null)
the error occurs on the last argument, it states:
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’
EDIT: I have removed the ? and now receive a very similar error, I also made an unimportant change to another argument. it now reads as follows:
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’
You don’t need to make
EventHandlernullable. Remove the?in the definition.The exception says
System.EventHandlermust be a non-nullable value type. SinceEventHandleris a class, or reference type, it obviously cannot be a value type and is, by convention nullable.