检查列表是否包含大于C#中的值的项

Aya*_*hby 4 .net c# linq contains list

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

ken*_*n2k 16

使用LINQ:

bool contains = yourList.Any(z => z.YouProperty > yourValue);
Run Code Online (Sandbox Code Playgroud)


Son*_*nül 5

您可以使用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);
Run Code Online (Sandbox Code Playgroud)