Performance of LINQ Any vs FirstOrDefault != null

后端 未结 7 1771
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-28 12:05

There are multiple places in an Open Source Project (OSP) code I contribute, where it has to be determined if an element in a collection satisfies a certain condition.

7条回答
  •  庸人自扰
    2020-11-28 12:19

    Although it has similar implementation, I believe Any is a bit faster because it doesn't have to return an object, which in some cases may be rich, with state and behavior, depends on how well the query is thought out.

提交回复
热议问题