How can I find if my list contains one and only one item without Count
or Single
?
Possible dupe of Efficient Linq Enumerable's 'Count() == 1' test
How about this:
int limitedCount = myEnumerable.Take(2).Count();
That will give you:
... but it gives you those answers whilst only iterating over the sequence once. You can then switch on the results.
myEnumerable.Take(2).Count() < 2
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