How to use List<T>.Find() on a simple collection that does not implement Find()?

Posted by Bilal on Stack Overflow See other posts from Stack Overflow or by Bilal
Published on 2010-04-07T13:53:20Z Indexed on 2010/04/08 8:23 UTC
Read the original article Hit count: 287

Filed under:
|

Hi, I want to use List.Find() on a simple collection that does not implement Find(). The naive way I thought of, is to just wrap it with a list and execute .Find(), like this:

ICollection myCows = GetAllCowsFromFarm(); // whatever the collection impl. is...
var steak = new List<Cow>(myCows).Find(moo => moo.Name == "La Vache qui Rit");

Now, 1st of all I'd like to know, C#-wise, what is the cost of this wrapping? Is it still faster to 'for' this collection the traditional way?

Second, is there a better straightforward way elegantly use that .Find()?

Cheers!

© Stack Overflow or respective owner

Related posts about c#3.0

Related posts about generics