Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Question of reason for rule "return value void for event handling delegates"

Question of reason for rule "return value void for event handling delegates"

Scheduled Pinned Locked Moved C#
regexquestion
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Chamundi
    wrote on last edited by
    #1

    Hi, lately I worked on some applications using the Model View Preseter Pattern combined with events with return values to refresh Gui controls. It works pretty good so I´m wondering why there is a convention saying events should have the return value 'void'. I would appreciate if someone could explain the reason for that rule... Thx in advance... Chamundi

    K L 2 Replies Last reply
    0
    • C Chamundi

      Hi, lately I worked on some applications using the Model View Preseter Pattern combined with events with return values to refresh Gui controls. It works pretty good so I´m wondering why there is a convention saying events should have the return value 'void'. I would appreciate if someone could explain the reason for that rule... Thx in advance... Chamundi

      K Offline
      K Offline
      kstls
      wrote on last edited by
      #2

      http://msdn.microsoft.com/en-us/library/4b612y2s.aspx[^] An event is an association between a delegate and a member function (event handler) that responds to the triggering of the event and allows clients from any class to register methods that comply with the signature and return type of the underlying delegate. The delegate can have one or more associated methods that will be called when your code indicates that the event has occurred. An event in one program can be made available to other programs that target the .NET Framework common language runtime So in short, the delegate is a multicast delegate, and can have more than one method attached and this is basicly the reason that it must be void. Hope it makes sence :)

      1 Reply Last reply
      0
      • C Chamundi

        Hi, lately I worked on some applications using the Model View Preseter Pattern combined with events with return values to refresh Gui controls. It works pretty good so I´m wondering why there is a convention saying events should have the return value 'void'. I would appreciate if someone could explain the reason for that rule... Thx in advance... Chamundi

        L Offline
        L Offline
        Luc Pattyn
        wrote on last edited by
        #3

        when more than one delegate is added to an event, they all get fired; which return value would you hope to get? :)

        Luc Pattyn [Forum Guidelines] [My Articles]


        DISCLAIMER: this message may have been modified by others; it may no longer reflect what I intended, and may contain bad advice; use at your own risk and with extreme care.


        C 1 Reply Last reply
        0
        • L Luc Pattyn

          when more than one delegate is added to an event, they all get fired; which return value would you hope to get? :)

          Luc Pattyn [Forum Guidelines] [My Articles]


          DISCLAIMER: this message may have been modified by others; it may no longer reflect what I intended, and may contain bad advice; use at your own risk and with extreme care.


          C Offline
          C Offline
          Chamundi
          wrote on last edited by
          #4

          Thx for the quick answer...considering the multicast issue of delegates/events and the reusability of assemblies it makes sense using a void return value...

          L 1 Reply Last reply
          0
          • C Chamundi

            Thx for the quick answer...considering the multicast issue of delegates/events and the reusability of assemblies it makes sense using a void return value...

            L Offline
            L Offline
            Luc Pattyn
            wrote on last edited by
            #5

            you're welcome. BTW: void is not a value, it is a type (or absence thereof, some would say). :)

            Luc Pattyn [Forum Guidelines] [My Articles]


            DISCLAIMER: this message may have been modified by others; it may no longer reflect what I intended, and may contain bad advice; use at your own risk and with extreme care.


            C 1 Reply Last reply
            0
            • L Luc Pattyn

              you're welcome. BTW: void is not a value, it is a type (or absence thereof, some would say). :)

              Luc Pattyn [Forum Guidelines] [My Articles]


              DISCLAIMER: this message may have been modified by others; it may no longer reflect what I intended, and may contain bad advice; use at your own risk and with extreme care.


              C Offline
              C Offline
              Chamundi
              wrote on last edited by
              #6

              Oh...yepp...I know...sorry for my unclear expression...I´m no native English speaker...

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups