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!
I think that LINQ is a major change to .NET and it is a very powerful tool.
I use LINQ to XML in production to parse and filter records from a 6MB XML file (with 20+ node levels) into a dataset in two lines of code.
Before LINQ this would have taken hundreds of lines of code and days to debug.
That's what I call elegant!
Working with attributes:
The
GetAttributes
extension method:AttributeSelection
is production code and also definesGetAttribute
andHasAttribute
. I chose to use thelet
andwhere
clauses in this example.