Simple example for multicast Delegate

Posted by Susanthampy under ASP.NET category on | Points: 40 | Views : 4277
using System;

delegate string StrMod(ref string str);

class MultiCastDemo {
static string replaceSpaces(ref string a) {
return a;

static string removeSpaces(ref string a) {
return a;

static string reverse(ref string a) {
return a;

public static void Main() {
StrMod strOp;
StrMod replaceSp = new StrMod(replaceSpaces);
StrMod removeSp = new StrMod(removeSpaces);
StrMod reverseStr = new StrMod(reverse);
string str = "This is a test";

// Set up multicast.
strOp = replaceSp;
strOp += reverseStr;

// Call multicast.
strOp(ref str);

// Remove replace and add remove.
strOp -= replaceSp;
strOp += removeSp;

str = "This is a test."; // reset string

// Call multicast.
strOp(ref str);

Comments or Responses

Posted by: T.saravanan on: 5/19/2011 Level:Silver | Status: [Member] [MVP] | Points: 10

kindly post your code inside the code tag.
Posted by: Karaniscool on: 5/20/2011 Level:Starter | Status: [Member] | Points: 10

Can you give any example of real world scenario where multi-cast delegates can be used..

Login to post response