what is a callback function?

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


Please Help Members By Posting Answers For Below Questions

Is boxing an implicit conversion?

628


What is the task perform by clr?

658


Can we inherit singleton class in c#?

544


What is hashset c#?

577


What is data bind in c#?

617






What is fcl in c#?

562


Can you inherit multiple classes in c#?

589


Is c# dictionary a hash table?

555


What is difference between property and variable in c#?

539


What are verbatim strings in c#?

579


Wcf and what is difference between wcf and web services?

582


Are c# tuples immutable?

585


Give an example to show for hiding base class methods?

542


is it possible to access a remote web service Without UDDI?

642


What is the property of class?

669