The best way to get a count of IEnumerable

前端 未结 11 1404
悲哀的现实
悲哀的现实 2020-12-14 15:47

Whats the best/easiest way to obtain a count of items within an IEnumerable collection without enumerating over all of the items in the collection?

Possible with LIN

11条回答
  •  既然无缘
    2020-12-14 16:16

    If you need to count and then loop you may be better off with a list.

    If you're using count to check for members you can use Any() to avoid enumerating the entire collection.

提交回复
热议问题