|
using
System;
namespace
delegations
{
//on
crée notre fonction déléguée(type delegate) avec comme arguments, ceux de la
méthode qu'elle devra accepter.
public delegate void
mamethode(int a);
class
Class1
{
[STAThread]
static void Main(string[]
args)
{
//on crée un objet de type mamethode(notre
fonction déléguée) et on lui file comme paramètre la fonction à pointer.
mamethode toto = new
mamethode(fonc1);
toto(10);
toto = new mamethode(fonc2);
toto(20);
Console.ReadLine();
}
public
static void
fonc1(int a)
{
Console.WriteLine("Dans ma fonction fonc1 il y a: {0}",a);
}
public
static void
fonc2(int b)
{
Console.WriteLine("Dans ma fonction fonc2 il y a: {0}",b);
}
}
}
|