Last Updated: February 25, 2016
·
991
· tomtheisen

Paramaterless delegates!

In C#, a parameterless delegate can accept any (or no) parameters.

Action<DateTime, BitArray> foo = delegate { 
    Console.WriteLine ("foo"); 
};

You can use this to assign event handlers where you don't care about the sender or event args.

Button1.Form1.Click += delegate { /* do something */ };

1 Response
Add your response

I didn't know that was valid. Thanks for the tip!

over 1 year ago ·