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

What is the and operator in c#?

697


What is difference between yielding and sleeping?

630


Explain the differences between static, void and public in c#?

733


What is a console device?

660


How do you prevent a method from being overridden in c#?

642


What is the difference between dataset and datatable in c#?

717


what is collections in .net? why we use?

1882


These questions were asked me in a technical interview: •If we deploy an application on multiple server (like database server, web server) then, each request should be redirected to proper server, then how you will handle it in your code? •How security pinholes will be handled in an application? •What things should be considered while writing a web application? •How will you do load/performance testing of web application? Which framework you will use for it? •How will you implement a cache for results which require a DB access? Please let me know how to write an web application considering all these points. I am not so much aware of architechural design of web application. Your guidelines will be helpful.

2732


What is base class in c#?

745


what is the difference between a struct and a class in c#?

777


Explain the Different types of configuration files in .net?

757


What is the difference between namespace and class in c#?

695


Illustrate the process of code compilation in c#?

676


Can a class have multiple constructors c#?

652


What is cookies in c# asp net?

670