Check if all items are the same in a List

后端 未结 5 1448
独厮守ぢ
独厮守ぢ 2020-12-02 22:11

I have a List(Of DateTime) items. How can I check if all the items are the same with a LINQ query? At any given time there could be 1, 2, 20, 50 or 100 items in the list.

5条回答
  •  庸人自扰
    2020-12-02 22:24

    My variant:

    var numUniques = 1;
    var result = list.Distinct().Count() == numUniques;
    

提交回复
热议问题