How to pass delegate as parameter

  • Thread starter Thread starter Gopal Prabhakaran
  • Start date Start date
G

Gopal Prabhakaran

Pls Help me - Asap

public void start(delegate wm,string name) - is this possiable ?

if so

Pls tell me how to do?
r - give some sample codes?
r - tell me some sites to learn?


Thanx
Gopal Prabhakaran
 
Gopal Prabhakaran said:
Pls Help me - Asap

public void start(delegate wm,string name) - is this possiable ?

if so

Pls tell me how to do?
r - give some sample codes?
r - tell me some sites to learn?
Sure, its possible. Basically, a delegate is a type just like any other, so
you would do something like:
//define your delegate type
public delegate void MyDelegate();
//define the method that takes the delegate
public void start(MyDelegate del, string name)
{

}

to call it, the code would be
start(new MyDelegate(TestMethod),"name");
public void TestMethod()
{
}
 
ok, how to do if have 2 classes means.
I have a class a and class b,

i want to pass a delegate (i.e method) to classb

pls help me asap

Thanx
Prabhakaran.G
 
Gopal Prabhakaran said:
ok, how to do if have 2 classes means.
I have a class a and class b,

i want to pass a delegate (i.e method) to classb
in that case you want to do a fully qualified name passed
class A
{
public void MyMethod(MyDelegate del);
}
class B
{
public void callMethod()
{
}
}
the code would be:
A a = new A();
B b = new B();
a.MyMethod(new MyDelegate(b.callMethod));
 
Back
Top