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
2009-07-31 14:14:09
+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
2009-07-31 14:16:08
+4
A:
They are distinct:
Select
is all about transformation.
Where
is all about filtering.
bruno conde
2009-07-31 14:20:22