what are delegates? How you used then in your project?

Answer Posted / prashanth

Delegate means function pointer.
There are two types of delegate
1-simple delegate
2-multicast delegate.

for simple ex:

private void Page_Load(object sender, System.EventArgs e)
{
Label2.Text= DoAction(new Action(Add)).ToString();
Response.Write ("<BR>");
Label3.Text= DoAction(new Action(Sub)).ToString();
//
// // Put user code to initialize the page here
}

static int DoAction(Action action)
{
return action(5,2);
}
public int Add(int n,int m)
{
return n+m;
}
public int Sub(int n,int m)
{
return n-m;
}

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the use of xmlserializer?

647


Can we overload the main method in c#?

676


Explain the difference between event and a delegate in c#?

728


What is main thread in c#?

686


Why c# is called type safe language?

635


What is an assembly in .net?

749


What is the object class in c#?

694


Explain the difference between abstract class and interface.

837


Does c# have its own class library?

719


What are interfaces in c#?

692


What is get set in c#?

748


Is int a class in c#?

719


What does typeof return c#?

706


What is difference between array and arraylist in c#?

649


Can abstract class have constructor in c#?

699