Hi...
I know delegate concept in c# but I want to know meaning of "multicast" in delegate ? Please explain with an example ?
Thanks.....
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
VulpesPosted Jan 2, 2012, 4:27 AM
All delegates in C# have multicast capability so you don't need to do anything special to have this functionality 'on tap'.
Here's a simple example I recently did in another thread:
http://www.c-sharpcorner.com/Forums/Thread/153505/delegate-in-C-Sharp.aspx
Vineet Kumar SainiPosted Jan 8, 2012, 11:33 PM
Nipun TomarPosted Jan 3, 2012, 12:32 AM
I think these Articles links are helpful plz read this:
http://www.netsplore.com/PublicPortal/blog.aspx?EntryID=9
http://www.c-sharpcorner.com/UploadFile/ankithakur/Delegates06042007014105AM/Delegates.aspx
Thanks
Hemant KumarPosted Jan 2, 2012, 4:09 AM
A multicast delegate can be assigned and invoke multiple methods.
You may have seen hints of this in your code. For example, if you are doing ASP.NET development and have ever looked at a page's InitializeComponent() method, you may have noticed a statement like this:
this.SearchButton.Click += new System.EventHandler(this.SearchButton_Click);
Notice the += in that statement. That is a clue. You could add another event handler if you wanted, and it would get called as well. For example, let's say you wanted to also call a method named NotifyStatistics every time the Search button was clicked. Then your code could be:
this.SearchButton.Click += new System.EventHandler(this.SearchButton_Click);
this.SearchButton.Click += new System.EventHandler(this.NotifyStatistics);
Every time the user clicks the Search button, first SearchButton_Click() is called, followed by NotifyStatistics(). The event handlers are called in the order they are added. Likewise, using -=, an event handler can be removed.
Now, you may be asking, why not just add whatever code is in the NotifyStatistics method to the SearchButton_Click method?
http://stackoverflow.com/questions/2192219/simple-delegate-delegate-vs-multicast-delegates