How to defien event in an Interface

  • Thread starter Thread starter Sergey Muschin
  • Start date Start date
S

Sergey Muschin

Hi there!

How to define event in an Interface and then to implement it in a class?



Thank You
 
Hi,

public interface II
{
event EventHandler e;
}

public class C: II
{
#region II Members

public event System.EventHandler e;

#endregion

}

once you state that the class will implement the interface the IDE will give
you option of pressing 'TAB' to implement the stubs for the interface

cheers,
 
Yes.... EventHandler , I know.....


But i need to send an additional parameter :) , besides Object and
EventArgs.
 
It's the same

Take a look at this code:

public delegate void MyHandler( object sender, EventArgs e, string other);

public interface II
{
event MyHandler Event;
}
public class MyClass: II
{
#region II Members

public event CTP.MyHandler Event;

#endregion

}

you just define the delegate as you need, take a look at MSDN regarding
delegates and consuming events.

cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
 
Sergey Muschin said:
Yes.... EventHandler , I know.....

But i need to send an additional parameter :) , besides Object and
EventArgs.

In that case you need to define your own parameter type, and then
declare a delegate which accepts that parameter type. Then you can
declare an event of the type of the delegate (rather than
EventHandler).
 
Back
Top