Array.Count() much slower than List.Count()

前端 未结 4 1872
梦如初夏
梦如初夏 2021-02-01 18:00

When using the extension method of IEnumerable Count(), an array is at least two times slower than a list.

Function                      Co         


        
4条回答
  •  别那么骄傲
    2021-02-01 18:26

    That is because int[] requires casting, while List does not. If you were to use Length property then result will be quite different - approx. 10x faster than List.Count().

提交回复
热议问题