What is multi caste delegate in c#

Posted by Jitendrasoft09 under C# on 6/26/2013 | Points: 10 | Views : 580 | Status : [Member] [MVP] | Replies : 2
Hi All,
I want to understand What is multi caste delegate in c#, let me know if anybody knows.

Jitendra Kumar
If my post helps you, plz mark as an answer.



Responses

Posted by: Satyapriyanayak on: 6/26/2013 [Member] [MVP] Silver | Points: 25

Up
0
Down
http://www.codeproject.com/Articles/31400/NET-Multicast-Delegates

If this post helps you mark it as answer
Thanks

Jitendrasoft09, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Nadeemshaik on: 7/3/2013 [Member] Starter | Points: 25

Up
0
Down
Delegat es: It is Similar to C++ function pointers,
with in delegate Objects we can store the Methods

syntax for creating delega te: <access modifier> Delegtae <return type> <delegtaeName>(arguments);
syntax for creating Object for Deleg ate :<DelegateName? <objName> = new <DelegateName>(address of Method);


Types of Delegat es:

1. single Caste Delegate (We can Store only single Method)
2. Multi Caste Delegate (We can Store more than one Method)

Example on Single Caste Delega te:

using System;

namespace SingleCaste
{
public class class1
{
public int add(int a,int b)
{
return a+b;
}
}
//create Delegate
public delegate int mydelegate(int a,int b);
class program
{
static void Main (strings[] args)
{
class1 c1 = new class1();
mydelegate md = new mydelegate(c1.add)'
console.writeline("Add;"+md(4,5));
console.readline();
}
}
}

example program on MultiCaste Delega te:

using System;

namespace multicaste
{
public class class1
{
public void add(int a,int b)
{
console.writeline("add:"+(a+b));
}
public void sub(int a,int b)
{
console.writeline("sub:"+(a-b));
}
public void mul(int a,int b)
{
console.writeline("mul:"+(a*b));
}
}
//create Delegate
public delegate void MultiDel(int a,int b);
class program
{
static Void Main(String[] args)
{
class1 c1 = new class1();
MultiDel md = new MultiDel(c1.add);
md += c1.mul;
md += c1.sub; //+= is used to add method to delegate
md(1,2);
md -= c1.mul; //-= is used to remove method from delegate
md(4,5);
console.readline()
}
}
}

Jitendrasoft09, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response