Why can't I add a delegate to my interface?
It's the base of design in the Object Oriented Programming. These are basically declaring delegate types, so they don't belong in an Interface. You can use Event in Interface with Delegate type.
A Delegate is just another type, so you don't gain anything by putting it inside the interface. You shouldn't need to create your own delegates. Most of the time you should just use EventHandler, Func, Predicate, or Action.
Delegates and Interfaces are two distinct concepts in C#. Interfaces allow to extend some object's functionality, it's a contract between the interface and the object that implements it, while delegates are just safe callbacks, they are a sort of function pointers.
You can use any of these:
public delegate double CustomerDelegate(int test); public interface ITest { EventHandler<EventArgs> MyHandler{get;set;} CustomerDelegate HandlerWithCustomDelegate { get; set; } event EventHandler<EventArgs> MyEvent; }
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