So, I know that Find() is just a List<T> method, whereas First() is an extension for any IEnumerable<T> . I also know that First() will return the first element if the parameter is not passed, whereas Find() will throw an exception. Finally, I know that First() will throw an exception if the item is not found, whereas Find() will return the default value of the type.
I hope this confuses what I actually ask. This is a matter of computer science and applies to these methods at the computational level. I realized that IEnumerable<T> extensions do not always work as you would expect under the hood. So, here is Q, and I mean from the point "close to metal": what is the difference between Find() and First() ?
Here is some code to provide basic assumptions to work on this.
var l = new List<int> { 1, 2, 3, 4, 5 }; var x = l.First(i => i == 3); var y = l.Find(i => i == 3);
Is there any actual computational difference between the way First() and Find() find their values ββin the above code?
Note. Let's now ignore things like AsParallel() and AsQueryable() .
Squirrelsama Dec 06 '10 at 17:12 2010-12-06 17:12
source share