How to make overloads of delegates?

Assume I want to have one subject delegate to inform observers about some event, but not every listeners needs to take a parameters. I tried doing overloads like in normal methods, but it gives me an error:

public delegate void LayerChange(Layer layer);        
public delegate void LayerChange();                          // Error 'Duplicate definition'
public event LayerChange OnLayerChange;             

Do I need to declare another delegate and launch both events?

public delegate void LayerChange(Layer layer);
public event LayerChange OnLayerChange;

public delegate void LayerChange2();
public event LayerChange2 OnLayerChange2;

Or shouldn’t be worried about that, do one delegate and just ignore paramater in those observersI don’t need it?

The latter.

Just ignore the parameter that is sent when you don’t need it. Creating two events for the same thing would be overkill.

Also, you don’t need to prefix your topic title(s) with “[Question]”, it just adds clutter to the forum. Your topic title was a question, indicated by the question mark. :slight_smile:

Privacy & Terms