【问题标题】:check whether the list contains item greater than a value in C# [closed]检查列表是否包含大于 C# 中的值的项目 [关闭]
【发布时间】:2012-12-07 23:59:35
【问题描述】:

我需要检查列表是否包含大于特定值的值。我怎么能这样做?

【问题讨论】:

标签: c# .net linq list contains


【解决方案1】:

您可以使用Enumerable.Any<TSource> 方法。它返回boolean

确定一个序列是否包含任何元素。

Return Value
Type: System.Boolean
true if the source sequence contains any elements; otherwise, false.

List.Any(a => a.Property > Value);

【讨论】:

    【解决方案2】:

    使用 LINQ:

    bool contains = yourList.Any(z => z.YouProperty > yourValue);
    

    【讨论】:

      猜你喜欢
      • 2023-03-26
      • 1970-01-01
      • 2020-04-02
      • 1970-01-01
      • 2012-08-26
      • 1970-01-01
      • 1970-01-01
      • 2020-05-09
      • 1970-01-01
      相关资源
      最近更新 更多