C# Multicast Delegates Tutorial with Programming Example

9gmrl-copy
In this chapter you will learn:

  • What is multicast delegate?
  • How to initialize c# multicast delegates?
  • Programming Example

What is Multicast Delegate?

Multicast Delegate is an extension of normal delegates. It combines more than one method at a single moment of time.

Important Fact about Multicast Delegate

  1. In Multicasting, Delegates can be combined and when you call a delegate, a whole list of methods is called.
  2. All methods are called in FIFO (First in First Out) order.
  3. + or += Operator is used for adding methods to delegates.
  4. or -= Operator is used for removing methods from the delegates list.



  • Programming Example

    Output

    1st Message is : Hello Multicast Delegates
    2nd Message is : Hello Multicast Delegates
    3rd Message is : Hello Multicast Delegates
    ———————-
    1st Message is : Message 2 Removed
    3rd Message is : Message 2 Removed

    Explanation

    This is the very basic example of Multicast delegates.

    1. Delegates Created
    2. Created 3 functions
    3. Created Delegate’s Object in Main method
    4. All the methods are added to delegates object.

      Print Delegates
    5. Remove message2(string msg) from delegates

    Summary

    In this chapter you learned about multicast delegates in c#. In the next chapter you will learn very important topics in c# – Event Handling.


    Leave a Reply

    Your email address will not be published. Required fields are marked *