CreateDelegate and DynamicInvoke

image_pdfimage_print
   
 

using System;
using System.Reflection;

delegate void theDelegate(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() {
        Type tObj = typeof(System.MulticastDelegate);
        MyClass obj = new MyClass();
        Delegate del = Delegate.CreateDelegate(typeof(theDelegate), obj,"MethodA");
        del.DynamicInvoke(new object[] { 1, 2 });
    }
}