Count number of element in List>

前端 未结 4 1305
野性不改
野性不改 2021-02-12 07:53

I have a List>. How can I count all the elements in this as if it was a single List in the fastest way?

So far I h

4条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-02-12 08:36

    By using LINQ, I think your code is good with a bit changes that no need for .ToList(), just call Count() extension as the following:

    int result = listOfLists.SelectMany(list => list).Distinct().Count();
    

提交回复
热议问题