Created
January 13, 2012 05:45
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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