coding for delegates?

Answer Posted / m.shanmuga sundaram

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
public delegate int execute(int a, int
b); //declare a delegate method

static void Main(string[] args)
{
Program p = new Program();

execute ex = new execute(p.add);
Console.WriteLine(ex(2,3)); //add method is
executed

ex = new execute(p.subtract);
Console.WriteLine(ex(2, 3)); //subtract method
is executed
}

public int add(int a, int b)
{
return (a + b);
}

public int subtract(int a, int b)
{
return (a - b);
}
}
}

Is This Answer Correct ?    3 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How do you prevent a class from being inherited in c#?

454


What is single dimensional array in c#?

504


How long can a string be c#?

511


What does out mean in c#?

508


What is mvc pattern in c#?

519






What is ispostback c#?

484


What is dataadapter c#?

481


What is semaphore in c#?

516


how to insert the data from the grid view to database table though button click.pls send the answer to mail id suri1319@gmail.com

1496


What is the and operator in c#?

493


Why is main static in c#?

520


What are the types of constructors?

508


What is datareader c#?

497


What are examples of desktop applications?

507


What is console writeline in c#?

471