i know everyone says to avoid doing something like this because its very slow (just to find out if there is 0)
IEnumerable<MyObject> list;
if (list.Count() > 0)
{
}
but what is the best alternative when all i need to do is find out if the list has a count of 0 or if there are items in it
Use list.Any()
. It returns true if it finds an element. Implementation wise, it would be:
using (var enumerator = list.GetEnumerator())
{
return enumerator.MoveNext();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With