Generic List, items counting with conditional-statement

后端 未结 1 387
情歌与酒
情歌与酒 2020-12-19 11:31

I have a Generic List. it has a ListfilesToProcess.Count property which returns total number of items, but I want to count certain number of items in list with conditional-s

相关标签:
1条回答
  • 2020-12-19 12:16

    Yes, use LINQ's Count method, with the overload taking a predicate:

    int count = ListFilesToProcess.Count(item => item.IsChecked);
    

    In general, whenever you feel you want to get rid of a loop (or simplify it) - you should look at LINQ.

    0 讨论(0)
提交回复
热议问题