Sunday, December 18, 2005

.NET 2.0 Goodies

I’ve finally started to work with .NET 2.0. I know, it’s considered very late, but I had my reasons...
Anyway, here is one line of code I had to use today that makes use of several new features I find very cool (and useful):

Array.ForEach(threads, delegate(Thread t) { t.Join(); });

Assuming you have an array of threads named ‘threads’, this line will make sure you wait for all of them to complete. It uses Generics, Anonymous Methods and Anonymous Delegates all at once…

2 comments:

Anonymous said...

What, as opposed to

foreach ( Thread t in threads ) t.Join();

:-)
Also, please remove the popup from the comments if possible - it doesn't work well with some RSS readers (RSSOwl for instance).

Ilan Assayag said...

You're right of course...
I was having so much fun trying out the new features in .NET 2.0 that I got blinded.
A friend of mine would have called what I did: reaching your teeth through your ass... (forgive my French)

I've removed the popup from the comment. Hope it's better now.