tags:

views:

88

answers:

2

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
I just wanted to know whether we can implement delegates and event handling in Interface also as in normal classes.
Bhaskar
+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