Why events, why not just delegates?

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

    #1

    Why events, why not just delegates?

    It is still unclear to me why we would use events when delegates seem to do
    just fine. People say that events make it so the publisher doesn't need to
    know about the listeners. What does that mean? Why are events better than
    delegates? Thanks


  • Jay B. Harlow [MVP - Outlook]

    #2
    Re: Why events, why not just delegates?

    Marty,
    The way I understand it Events are to Delegate fields that Properties are to
    other fields.

    The event encapsulates & protects the underlying delegate value.

    Chris Sells' book "Windows Forms Programming in C#" from Addison Wesley has
    a chapter explaining the relationship. The story is also available on Code
    Project:



    Hope this helps
    Jay

    "Marty McDonald" <mcdonama@wsdot .wa.gov> wrote in message
    news:%23mWo1hZm DHA.2776@tk2msf tngp13.phx.gbl. ..[color=blue]
    > It is still unclear to me why we would use events when delegates seem to[/color]
    do[color=blue]
    > just fine. People say that events make it so the publisher doesn't need[/color]
    to[color=blue]
    > know about the listeners. What does that mean? Why are events better than
    > delegates? Thanks
    >
    >[/color]


    Comment

    • Jay B. Harlow [MVP - Outlook]

      #3
      Re: Why events, why not just delegates?

      Marty,
      I just found the story on Chris Sells web site itself, where I was
      originally looking for it.

      http://www.sellsbrothers.com/writing...=delegates.htm

      Same story, different location & formatting.

      Hope this helps
      Jay

      "Marty McDonald" <mcdonama@wsdot .wa.gov> wrote in message
      news:%23mWo1hZm DHA.2776@tk2msf tngp13.phx.gbl. ..[color=blue]
      > It is still unclear to me why we would use events when delegates seem to[/color]
      do[color=blue]
      > just fine. People say that events make it so the publisher doesn't need[/color]
      to[color=blue]
      > know about the listeners. What does that mean? Why are events better than
      > delegates? Thanks
      >
      >[/color]


      Comment

      • Peter Huang

        #4
        RE: Why events, why not just delegates?

        Hi Marty,

        Jay's link is very good.
        You may also take a look at the links below.

        Events Tutorial
        http://msdn.microsoft.com/library/de...us/csref/html/
        vcwlkEventsTuto rial.asp
        Delegates Tutorial
        http://msdn.microsoft.com/library/de...us/csref/html/
        vcwlkdelegatest utorial.asp

        Raising Events and Responding to Events
        http://msdn.microsoft.com/library/de...us/dndotnet/ht
        ml/raiserespeven.a sp
        Events and Delegates
        http://msdn.microsoft.com/library/de...us/cpguide/htm
        l/cpconeventsdele gates.asp

        If you have any related question, please post here.

        Regards,
        Peter Huang
        Microsoft Online Partner Support
        Get Secure! www.microsoft.com/security
        This posting is provided "as is" with no warranties and confers no rights.
        --------------------[color=blue]
        >From: "Marty McDonald" <mcdonama@wsdot .wa.gov>
        >Subject: Why events, why not just delegates?
        >Date: Thu, 23 Oct 2003 12:01:13 -0700
        >Lines: 6
        >X-Priority: 3
        >X-MSMail-Priority: Normal
        >X-Newsreader: Microsoft Outlook Express 6.00.2600.0000
        >X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000
        >Message-ID: <#mWo1hZmDHA.27 76@tk2msftngp13 .phx.gbl>
        >Newsgroups: microsoft.publi c.dotnet.genera l
        >NNTP-Posting-Host: 164.110.202.164
        >Path: cpmsftngxa06.ph x.gbl!TK2MSFTNG P08.phx.gbl!tk2 msftngp13.phx.g bl
        >Xref: cpmsftngxa06.ph x.gbl microsoft.publi c.dotnet.genera l:113005
        >X-Tomcat-NG: microsoft.publi c.dotnet.genera l
        >
        >It is still unclear to me why we would use events when delegates seem to do
        >just fine. People say that events make it so the publisher doesn't need to
        >know about the listeners. What does that mean? Why are events better than
        >delegates? Thanks
        >
        >
        >[/color]

        Comment

        • Peter Huang

          #5
          RE: Why events, why not just delegates?

          Hi Marty,

          If you still have questions on this issue, please reply the thread to let
          us know you need further assistance.

          Regards,
          Peter Huang
          Microsoft Online Partner Support
          Get Secure! www.microsoft.com/security
          This posting is provided "as is" with no warranties and confers no rights.

          Comment

          Working...