Multicast delegate C#

后端 未结 3 1559
栀梦
栀梦 2021-02-10 16:20

Am studying about delegates. As I read. I learned that adding more than one function in a delegate is called multicast delegate. Based on that I wrote a program. Here two functi

3条回答
  •  闹比i
    闹比i (楼主)
    2021-02-10 16:55

    Yes, it's an example of a multicast delegate. Note that instead of

    new MyDelegate(AddNumbers)
    

    you can typically say just

    AddNumbers
    

    because a so-called method group conversion exists that will create the delegate instance for you.

    Another thing to note is that your declaration public delegate void MyDelegate(int a, int b); does not have to reside inside another type (here inside the MainPage class). It could be a direct member of the namespace (since it's a type). But of course it's perfectly valid to "nest" it inside a class, as you do, for reasons similar to the reason why you create nested classes.

提交回复
热议问题