Ignore delegate parameter System.Action?

I have it:

public event Action<BaseCommodity> OnGatherActionSelected = delegate { };
gmp.OnGatherActionSelected += m_Worker.CharacterActions.StartGatherMaterials; // << takes a parameter

but now I want to use the event to call a method that takes 0 parameters

gmp.OnGatherActionSelected += ParentPanel.RedrawUI; // does not take parameters .. DOES NOT WORK :(

How can i do this?

+4
source share
2 answers

The easiest option is to add a handler that takes a parameter and ignores it, delegating the method you want to use:

gmp.OnGatherActionSelected += _ => ParentPanel.RedrawUI();
+5
source

You can wrap it in a method that takes a parameter:

gmp.OnGatherActionSelected += x => ParentPanel.RedrawUI();
+4
source

Source: https://habr.com/ru/post/1611156/


All Articles