Associating the delegate with an anonymous method.

image_pdfimage_print
   
 


delegate void Printer(string s);

class TestClass
{
    static void Main()
    {
        Printer p = delegate(string j)
        {
            System.Console.WriteLine(j);
        };

        p("this is a test.");

    }
    static void DoWork(string k)
    {
        System.Console.WriteLine(k);
    }
}