views:

480

answers:

4

In linq there is the Select and Where methods. What should every developer know about these two methods (Example: when to use one over the other, any advantages over the other, etc)

+3  A: 

Select maps an enumerable to a new structure. If you perform a select on an IEnumerable, you will get an array with the same number of elements, but a different type depending on the mapping you specified. Where filters the IEnumerable so that it gives you a subset of the original IEnumerable.

Steve
+4  A: 

Where

finds items that match and only returns those that do.

-> IEnumerable<A> in, IEnumerable<A> out

Select

returns something for all items in the source. That something might be the items themselves, but are more usually a projection of some sort.

-> IEnumerable<A> in, IEnumerable<B> out

Drew Noakes
+4  A: 

They are distinct:

Select is all about transformation.

Where is all about filtering.

bruno conde
+2  A: 
Bruno Reis