>> Functions that are triggered when an associated event happens.
Example :
------------
> In C, functionpointeris used as a callback functions.
> In C++,virtual functionis used as a callback function.
> c#,delegatekeyword 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);
}
}
}
0
comments:
Post a Comment
Tu comentario será moderado la primera vez que lo hagas al igual que si incluyes enlaces. A partir de ahi no ser necesario si usas los mismos datos y mantienes la cordura. No se publicarán insultos, difamaciones o faltas de respeto hacia los lectores y comentaristas de este blog.
0 comments:
Post a Comment