The database uses of LINQ (to SQL/to Entities) get all of the glory, but LINQ can be used against your run of the mill objects in .NET. Take for example sorting strings;
1 |
static void Main(string[] args)
orderby friend select friend;
|
The interesting part is on lines 13/14 - we get a list of sorted strings by executing SQL like syntax on our string array. Lets try something else, lets sort the list based on who's got the longest name, sorting from longest to shortest: Notice I'm also using anonymous types in the following example( var ).
1 |
static void Main(string[] args)
|
Easy, but very useful. You can use LINQ to sort collections of objects and do all sorts of powerful and useful things.
No comments:
Post a Comment