C#C
C#3y ago
Hugh

✅ Assigning an Action to a delegate

I have an Action<> that is defined as:

using DataChangedCallbackFunc = Action<string, MyData>;


I want to have a delegate in my class that can call multiple of these actions.

My initial attempt was to do:
public delegate void DataChangedDelegate(string name, MyData data);
private DataChangedDelegate _dataChangedDelegate;
public void AddDataChangedCallback(DataChangedCallbackFunc dataChangedCallbackFunc)
{
    _dataChangedDelegate += dataChangedCallbackFunc;
}


However, this doesn't like it as it appears to be expecting a concrete (?) function rather than an Action<>.

How can I define my delegate in a way that it can have an Action<> added to it?

Google isn't helping me, as any results that include "action" and "delegate" are just pages talking about how an Action<> is a type of delegate
Was this page helpful?