The best way to get a count of IEnumerable

前端 未结 11 1410
悲哀的现实
悲哀的现实 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:04

    When I want to use the Count property, I use ILIST which implements IEnumerable and ICollection interfaces. The ILIST data structure is an Array. I stepped through using the VS Debugger and found that the .Count property below returns the Array.Length property.

    IList FileServerVideos = Directory.GetFiles(VIDEOSERVERPATH, "*.mp4"); 
    if (FileServerVideos.Count == 0)
        return;
    

提交回复
热议问题