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'
EventHandler is a reference type, therefore is inherently nullable. Should be:
public void AddItemToMainMenu(MenuItem parentMenu, MenuItems item, String menuItemText, bool isChecked, EventHandler eventHandler = null)
You don't need to make EventHandler nullable. Remove the ? in the definition.
The exception says System.EventHandler must be a non-nullable value type. Since EventHandler is a class, or reference type, it obviously cannot be a value type and is, by convention nullable.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With