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

From a versioning perspective, what are the drawbacks of extending an interface as opposed to extending a class?

512


Explain a MSIL ? Why is it appreciated by all developers?

582


What is the use of table aliases?

488


the c# keyword .int. Maps to which .net type?

743


What is static noise?

501






What is the difference between a variable and a literal?

533


Contrast System.String and System.Text.StringBuilder classes?

524


What is array and types of array in c#?

472


What is .cs file in c#?

518


Why is it called c sharp?

513


Can I use exceptions in c#?

537


What does int32 mean?

473


What is an assembly in dotnet?

544


How long can loop recorders stay in?

595


What is wpf application in c#?

460