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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
VulpesRank #55 · 29.2K reputationPosted Jan 1, 2012, 11:27 PM EST
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
Hemant KumarRank #1,202 · 1.5K reputationPosted Jan 1, 2012, 11:09 PM EST
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
Nipun TomarRank #90 · 23K reputationPosted Jan 2, 2012, 7:32 PM EST
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
Vineet Kumar SainiRank #257 · 9.8K reputationPosted Jan 8, 2012, 6:33 PM EST