Declaring an event in an interface

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Brad

    Declaring an event in an interface

    I'm using events to handle asynchronous notification upwards and interfaces
    across all class boundaries. I'm not sure of how to declare a delegate and
    its associated event through the interface. I need to be able to declare
    this information in the interface so that the caller can register for the
    event. Am I missing something simple?

    TIA

    Brad


  • Brian Gideon

    #2
    Re: Declaring an event in an interface

    Brad,

    You can declare the event in the interface, but C# does not allow you
    to declare types in an interface so you'll have to declare the delegate
    somewhere else.

    public delegate void MyEventHandler( );

    public interface IMyInterface
    {
    event MyEventHandler MyEvent;
    }

    Brian

    Brad wrote:
    I'm using events to handle asynchronous notification upwards and interfaces
    across all class boundaries. I'm not sure of how to declare a delegate and
    its associated event through the interface. I need to be able to declare
    this information in the interface so that the caller can register for the
    event. Am I missing something simple?
    >
    TIA
    >
    Brad

    Comment

    • Ignacio Machin \( .NET/ C# MVP \)

      #3
      Re: Declaring an event in an interface

      Hi,

      I think you are :)

      this is a valid declaration :

      public interface A
      {
      event EventHandler ev;
      }


      --
      --
      Ignacio Machin,
      ignacio.machin AT dot.state.fl.us
      Florida Department Of Transportation

      "Brad" <brad.markisohn @roche.comwrote in message
      news:%23Vs3VMy2 GHA.1268@TK2MSF TNGP02.phx.gbl. ..
      I'm using events to handle asynchronous notification upwards and
      interfaces across all class boundaries. I'm not sure of how to declare a
      delegate and its associated event through the interface. I need to be
      able to declare this information in the interface so that the caller can
      register for the event. Am I missing something simple?
      >
      TIA
      >
      Brad
      >

      Comment

      Working...