Why use delegates?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • BobLewiston
    New Member
    • Feb 2009
    • 93

    Why use delegates?

    Why use delegates?

    I understand HOW to use delegates, but in what situations would you actually use them? The examples I see in the literature are all in situations where the code could just be written without ever using them.
  • PRR
    Recognized Expert Contributor
    • Dec 2007
    • 750

    #2
    Check this and MSDN...

    Comment

    • vekipeki
      Recognized Expert New Member
      • Nov 2007
      • 229

      #3
      If you can get the desired result through a static method, you have to use a delegate, because you cannot use interfaces with static methods. Delegate is represented only by a single method signature, and it doesn't care if that method is static or instance (a nice thing is also passing anonymous delegates, or Lambda expressions in C# 3.0).

      On the other hand, interfaces allow you to pass an object with some encapsulated state information, which you cannot do with static methods (ok, I guess you can have static properties also, but you get the point). Interfaces also contain multiple method and property signatures, when compared to a single delegate.

      Comment

      • todashah
        New Member
        • Feb 2008
        • 26

        #4
        In C# Console Application if u want to fire event then
        u have to compulsory declare delegate bcoz delegate
        is a base of any event & without delegate event is not
        possible in C# console application.

        I Hope your doubt is clarify...

        Comment

        Working...