Count number of element in List>

前端 未结 2 669
北荒
北荒 2021-02-12 08:19

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

2条回答
  •  猫巷女王i
    2021-02-12 08:30

    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();
    

提交回复
热议问题