Can we implement delegates and events in Interface?
A:
Yes, you can define them in an interface. No, you cant implement them in an interface.
Do you have a more specific problem?
leppie
2009-05-13 06:28:38
I just wanted to know whether we can implement delegates and event handling in Interface also as in normal classes.
Bhaskar
2009-05-20 19:40:13
+1
A:
You can specify an event in an interface, but you can't declare a delegate (or any other type) - at least not in C#. For instance:
// Valid
public delegate void BarHandler(object sender, EventArgs e);
public interface IFoo
{
event BarHandler Bar;
}
// Invalid
public interface IFoo
{
delegate void BarHandler(object sender, EventArgs e);
event BarHandler Bar;
}
Jon Skeet
2009-05-13 06:30:25