From Schmid.wiki
Jump to: navigation, search

Example

using System;
 
class Test
{
    delegate void StringMethod(string s); // declaration
    static void DoStuff(string s)
    {
        Console.WriteLine("doing stuff: " + s);
    }
    static void DoOtherStuff(string s)
    {
        Console.WriteLine("doing other stuff: " + s);
    }
    static void Main(string[] args)
    {
        // instantiation
        StringMethod sm1 = new StringMethod(DoStuff);
        StringMethod sm2 = new StringMethod(DoOtherStuff);

        // invocation
        sm1("yo");
        sm2("yo");
    }
}