小编Jar*_*sai的帖子

我可以在Linq结果上使用"Count"属性吗?

我的代码如下:

var result = from x in Values where x.Value > 5 select x;
Run Code Online (Sandbox Code Playgroud)

然后,我想检查一下:

if(result.Count > 0) { ... }
else if(result.Count == 1) { ... }
else { throw new Exception(...); }
Run Code Online (Sandbox Code Playgroud)

但是,我得到的错误如下:

error CS0019: Operator '==' cannot be applied to operands of type 'method group' and 'int'
Run Code Online (Sandbox Code Playgroud)

我可以不用结果写一个foreach吗?

c# linq

4
推荐指数
2
解决办法
8993
查看次数

标签 统计

c# ×1

linq ×1