Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Events IN Interfaces...

Status
Not open for further replies.

Milby7

Programmer
Dec 5, 2003
67
GB
Hi there!

I have a very quick question... Can you declare an event to be part of an interface?? e.g.

public interface IMyInterface
{
public event MyEventHandler MyEvent;
}

Thanks!!
 


From MSDN: "The static and public modifiers are not permitted on interface methods."

So you can write this
Code:
public interface IMyInterface
{
     event MyEventHandler MyEvent;
}

... and it works [afro]
 
There's an interesting reason for that. Since the purpose of an interface is to define a means of exposing functionality (and only that), scoping modifiers don't really apply: in effect, all the internals of an interface are public already. For example, it wouldn't make sense for an interface to specify a private method, since by definition it isn't exposed as a means of accessing functionality. To define it as public is superfluous.

Bob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top