Is the Linq Count() faster or slower than List.Count or Array.Length?

前端 未结 7 572
你的背包
你的背包 2020-11-29 04:59

Is the LINQ Count() method any faster or slower than List<>.Count or Array.Length?

7条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-29 05:45

    I would say it depends on the List. If it is an IQueryable that is a table in a db somewhere then Count() will be much faster because it doesn't have to load all of the objects. But if the list is in-memory i would guess that the Count property would be faster if not about the same.

提交回复
热议问题