Answer Posted / m.shanmuga sundaram
Definition:
***********
Functions that are triggered when an associated event
happens.
example
*******
a) In C language function pointer is used as a callback
functions.
b) In C++ virtual function are used as a callback function.
c) In c# delegate keyword is used to create a call back
function.
example in c#
*************
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 ? | 11 Yes | 1 No |
Post New Answer View All Answers
Can delegates be used as callbacks?
Write the syntax for catching an exception in c#?
What does question mark mean in c#?
How many types of interface are there in c#?
What is a function c#?
Why do we use virtual methods in c#?
Does constructor return any value in c#?
What is gridview c#?
What is difference between an reference type and value type in C#?
What is monitor in C#?
What is the default value of object in c#?
Can property be private in c#?
What is the purpose of escape sequence?
What is multicast delegate in c# ?
State whether it is true to test a Web service you must create a windows application or Web application to consume this service or not?