C# Difference between First() and Find()

前端 未结 5 1509
花落未央
花落未央 2020-12-08 19:08

So I know that Find() is only a List method, whereas First() is an extension for any IEnumerable. I als

5条回答
  •  [愿得一人]
    2020-12-08 19:36

    Since List<> is not indexed in any way, it has to go through all values to find a specific value. Therefore it doesn't make much of a difference compared to traversing the list via an enumerable (apart from the creation of a enumerable helper object instance).

    That said, keep in mind that the Find function was created way earlier than the First extension method (Framework V2.0 vs. V3.5), and I doubt that they would have implemented Find if the List<> class had been implemented at the same time as the extension methods.

提交回复
热议问题