Windows Forms: A cool use for extension methods and LINQ expressions.

Yesterday I responded to Paul Stovell’s post about Ruby for .NET developers, in that post I showed how you could use the LINQ expression with the List<T> object’s ForEach method to match what Paul had done with Ruby block syntax. While it still may not be able to write code quite like Scott Hanselman demonstrates I think that it goes a long way towards showing that C# isn’t a programming language with trainer-wheels.

One of the things that I wasn’t sure of yesterday was whether you could have an expression that returned a void value. Well, as I was reading my feeds this morning I stumbled across this post by Ido Samuelson titled Control.Invoke in C# 3.0.

Ido’s post is interesting because he combines extension methods, LINQ expressions and even method group conversion syntax (in an interim example) to show how you can more easily approach the challenges of calling back onto the message handling loop inside a windows application. I highly recommend looking at his post because I think it shows one of the useful areas where extension methods will be used outside of an application’s data path.

So – yes you can have void expressions, and as a matter of fact you can have void(void) expressions which means expression syntax is just a more concise version of anonymous method syntax.


One thought on “Windows Forms: A cool use for extension methods and LINQ expressions.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s