tags:

views:

79

answers:

1

Using a linq query/method chainging I wish to select just the first 2 Point objects in a List ordered by Point.X. How can I?

+8  A: 
myList.OrderBy(item => item.X).Take(2);

Breaking it down:

OrderBy() takes a lambda expression which selects the key by which to order. In this case, we want to return the .X property on the object. Another example is if we had a Person object and wanted to sort by .FirstName, the key selector would be (item => item.FirstName).

Take() truncates the enumeration to the specified number.

Rex M