This post originated from an RSS feed registered with .NET Buzz
by Jeff Key.
Original Post: Favorite C# 2.0 feature of the day: Anonymous Methods
Feed Title: Jeff Key
Feed URL: http://www.asp.net/err404.htm?aspxerrorpath=/jkey/Rss.aspx
Feed Description: Topics revolve around .NET and the Windows platform.
I haven't done anything particularly interesting with anonymous methods yet, but the simple fact that they reduce clutter in Windows Forms makes me one happy camper. Consider the following bit of code, something which you've probably seen a thousand times:
And now, the same thing (effectively) using an anonymous method:
You can define all of your event handlers inline in a single method, if you choose, and forward any calls to appropriately named methods.