IEnumerable的是空的? [英] IEnumerable is empty?
本文介绍了IEnumerable的是空的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道它可能不事关/影响大部分的性能,但是我讨厌得到的想法的的IEnumerable
和做 .Count之间的()
。是否有一个的IsEmpty
或 NotEmpty
或某种功能? (类似于STL空())
I know it probably doesnt matter/affect performance for the most part but I hate the idea of getting an IEnumerable
and doing .Count()
. Is there a IsEmpty
or NotEmpty
or some function? (similar to stl empty())
推荐答案
您想要的 IEnumerable.Any()扩展方法(.Net框架3.5及以上)。它避免了计算过的元素。
You want IEnumerable.Any() extension method (.Net Framework 3.5 and above). It avoids counting over the elements.
这篇关于IEnumerable的是空的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文