The "-" operator can be used to remove a component delegate from a multicast delegate.
1. Open Visual Studio go to>>File>>New>>Website>>Asp.net Empty Website and name anything but named DelegatesExplained:

2. Add New WebForm to your Project and Name DelegateExplained.aspx,you can name anything:

3. Add the following under the body tag of Desing page of DelegatesExplained.aspx:

3. Add the following under the body tag of Desing page of DelegatesExplained.aspx:
- <form id="form1" runat="server">
- <div>
- <asp:Label ID="Label1" runat="server"></asp:Label>
- <asp:Label ID="Label2" runat="server"></asp:Label>
- <asp:Label ID="Label3" runat="server"></asp:Label>
- </div>
- </form>
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- public delegate void Delegates();
- protected void Page_Load(object sender, EventArgs e)
- {
- }
- public void First()
- {
- Label1.Text = "First";
- }
- public void Second()
- {
- Label2.Text = "Second";
- }
- public void Third()
- {
- Label3.Text = "Third";
- }
6. Create Objects Of Delegate under pageload() method:
- protected void Page_Load(object sender, EventArgs e)
- {
- MultipleDelegate m1,m2,m3;
- }
- public void First()
- {
- Label1.Text = "First";
- }
- public void Second()
- {
- Label2.Text = "Second";
- }
- public void Third()
- {
- Label3.Text = "Third";
- }
7. Now add refrence of Function name First() to m1 and calling the function by calling m1():
- protected void Page_Load(object sender, EventArgs e)
- {
- MultipleDelegate m1;
- m1 = First; //adding reference to the First Function
- m2=Second; //adding reference to the SecondFunction
- m3=Third; //adding reference to the Third Function
- m1();
- m2();
- m3();
- }
- public void First()
- {
- Label1.Text = "First";
- }
- public void Second()
- {
- Label2.Text = "Second";
- }
- public void Third()
- {
- Label3.Text = "Third";
- }
Now run by pressing ctrl+f5;
Now see output will be:

Now Multicast Delegates by using + operator rather then calling each object separately create a new object m4 and add all the delegates objects in it.
Only delegates of the same type can be combined.
- protected void Page_Load(object sender, EventArgs e)
- {
- MultipleDelegate m1, m2, m3,m4;
- m1 = First; //adding reference to the First Function
- m2 = Second; //adding reference to the SecondFunction
- m3 = Third; //adding reference to the Third Function
- m4 = m1 + m2 + m3; //casting all three objects of MuticastDelegate to one object;
- m4();
- }
- public void First()
- {
- Label1.Text = "First";
- }
- public void Second()
- {
- Label2.Text = "Second";
- }
- public void Third()
- {
- Label3.Text = "Third";
- }

You Can also use the "-" operator to remove any object as given below:
Create new object m5:
- protected void Page_Load(object sender, EventArgs e)
- {
- MultipleDelegate m1, m2, m3,m4,m5;
- m1 = First; //adding reference to the First Function
- m2 = Second; //adding reference to the SecondFunction
- m3 = Third; //adding reference to the Third Function
- m4 = m1 + m2 + m3; //casting all three objects of MuticastDelegate to one object;
- m5 = m4 - m3;
- m5();
- }
- public void First()
- {
- Label1.Text = "First";
- }
- public void Second()
- {
- Label2.Text = "Second";
- }
- public void Third()
- {
- Label3.Text = "Third";
- }
Thanks.
Join the conversation! Your thoughts help the community grow.