Late Binding Delegates: A delegate is a repository of type-safe function pointers.
using System;
using System.Reflection;
delegate void XDelegate(int arga, int argb);
class MyClass {
public void MethodA(int arga, int argb) {
Console.WriteLine("MyClass.MethodA called: {0} {1}", arga, argb);
}
}
class Starter {
static void Main() {
MyClass obj = new MyClass();
XDelegate delObj = new XDelegate(obj.MethodA);
delObj.Invoke(1, 2);
delObj(3, 4);
}
}
Related examples in the same category