Performance of LINQ Any vs FirstOrDefault != null

后端 未结 7 1785
佛祖请我去吃肉
佛祖请我去吃肉 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:12

    Why should any continue after it has found an element satisfying the condition? If the condition applies to 1 element, that qualifies as "any".

    I think they should both perform about the same, but Any() does express your intention more clearly.

提交回复
热议问题