Is it possible to check if something is in a delegate?


delegate void Delegate();
Delegate List;


void Update () { List(); }

Adding and removing. Edit is a function.

List += Edit;
List -= Edit;

Is it possible to check if List, for example has Edit?

Is it also possible to use arguments, for example:

List += Edit(10);

Is it possible to check if List, for example has Edit?

Nope. You can’t verify that a method has already been added to your delegate. What you can do, if you don’t want to end up with duplicates is removing the method before adding it (if the method wasn’t already there, trying to remove it won’t cause an error). You, as the programmer, are responsible for removing methods from delegates when appropriate.

Is it also possible to use arguments?

Yes, it is possible, as long as you define those arguments in the signature of your delegate. Like this:

delegate void Delegate(int n);

Now you can only add methods that accept an int parameter to your delegate.

Note: Your last line of code is not correct. It won’t compile. You cannot call the method while adding it to the delegate.

List += Edit(10); //Incorrect. Will throw compiler error
//Arguments are passed when calling the delegate. Always check if the delegate contains 
//at least one method before calling it by checking that is is not null
if (List != null)
    List(10); //Correct

Hope this helps!

Edit: I stand corrected. Like @PizzaPie says, it is possible to get information on the methods added through the use of reflection.