SoFunction
Updated on 2025-03-01

Small examples of anonymous methods in c#


// Create a handler for a click event.
+= delegate( o, e)
                   { ("Click!"); };

 

// Create a delegate.
delegate void Del(int x);

// Instantiate the delegate using an anonymous method.
Del d = delegate(int k) { /* ... */ };

 

void StartThread()
{
    t1 = new
      (delegate()
            {
                ("Hello, ");
                ("World!");
            });
    ();
}