Bhaskar
Bhaskar

Reputation: 4259

Delegates and Events in Interface?

Can we implement delegates and events in Interface?

Upvotes: 1

Views: 1590

Answers (1)

Jon Skeet
Jon Skeet

Reputation: 1500515

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;
}

Upvotes: 6

Related Questions