Find() vs. Where().FirstOrDefault()

前端 未结 7 1875
南旧
南旧 2020-11-27 11:31

I often see people using Where.FirstOrDefault() to do a search and grab the first element. Why not just use Find()? Is there an advantage to the ot

7条回答
  •  再見小時候
    2020-11-27 12:17

    I just found out today, doing some tests on a list of 80K objects and found that Find() can be up to 1000% faster than using a Where with FirstOrDefault(). I didn't know that until testing a timer before and after each all. Sometimes it was the same time, otherwise it was faster.

提交回复
热议问题