Saw a post about hidden features in C# but not a lot of people have written linq/lambdas example so... I wonder...
What's the coolest (as in the most elegant) use of the C# LINQ and/or Lambdas/anonymous delegates you have ever saw/written?
Bonus if it has went into production too!
http://igoro.com/archive/extended-linq-additional-operators-for-linq-to-objects/
http://igoro.com/archive/7-tricks-to-simplify-your-programs-with-linq/
Some basic functionals:
Don't do much good if you don't know how to use them. In order to know that, you need to know what they're for:
The LINQ Raytracer certainly tops my list =)
I'm not quite sure if qualifies as elegant but it is most certainly the coolest linq-expression I've ever seen!
Oh, and just to be extremely clear; I did not write it (Luke Hoban did)
Progress Reporting for long running LINQ queries. In the blog post you can find an extension method WithProgressReporting() that lets you discover and report the progress of a linq query as it executes.
Perhaps not the coolest, but recently I have been using them anytime I have a block of code that gets C+Pd over and over again only to have a few lines change. For instance, running simple SQL commands to retrieve data can be done like so:
Which could return a list of Posts that were created today. This way I don't have to copy and paste the try-catch-finally block fifteen million times for each command, object, et cetera.
I did one (a bit crazy, but interesting) thing like that just recently: