检查列表中的所有项目是否相同 [英] Check if all items are the same in a List
本文介绍了检查列表中的所有项目是否相同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个 List(Of DateTime) 项目.如何使用 LINQ 查询检查所有项目是否相同?在任何给定时间,列表中可能有 1、2、20、50 或 100 个项目.
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.
谢谢
推荐答案
像这样:
if (list.Distinct().Skip(1).Any())
或
if (list.Any(o => o != list[0]))
(可能更快)
这篇关于检查列表中的所有项目是否相同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文