LINQ examples

Linq is sooo good.

The next time you loop a list or array to find a value or two; consider spending 15 minutes to learn some Linq; it is well invested.  The syntax is somewhat like SQL but more straight forward.  For instance the keywords are written "the normal" way.  First what you have (from), then the filtering (where) and finally what you want (select).

var query =
    from c in myCustomerList
    where c.Age < 42
    select c;

If you are looping two lists and compare them to get a new list, you should really look into Linq.  It will save you lots of time.

I found an old site at MSDN with some good examples here: http://msdn.microsoft.com/en-us/vcsharp/aa336746.aspx

1 comment:

Vipin Cherukara said...

For more on LINQ visit