Skip to content

Instantly share code, notes, and snippets.

@arttuladhar
Created January 13, 2012 05:45
Show Gist options
  • Save arttuladhar/1604835 to your computer and use it in GitHub Desktop.
Save arttuladhar/1604835 to your computer and use it in GitHub Desktop.
Multicast Deligate - It is a delegate which holds the reference of more than one method.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication2
{
class Program
{
delegate void Delegate_Multicase(int x, int y);
static void Method1(int x, int y)
{
Console.WriteLine("You are in Method 1");
Console.WriteLine("X :" + x + "\nY :" + y);
}
static void Method2(int x, int y)
{
Console.WriteLine("You are in Method 2");
Console.WriteLine("X :" + x + "\nY :" + y);
}
static void Main(string[] args)
{
Delegate_Multicase func = new Delegate_Multicase(Method1);
func += new Delegate_Multicase(Method2);
func(1, 2); //Method 1 and 2 are called
func -= new Delegate_Multicase(Method1);
func(2, 3);
Console.ReadLine(); //Pause
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment