I want to check if an enumeration contains 0, 1 or 1+ elements. I want to avoid the overhead of enumerating the entire sequence, thus want to avoid Count()
.
I know Linq query SingleOrDefault()
could be used for this purpose, but instead adds cumbersome exception handling in the 1+ case.
Any way to do it without Count()
and without exception handling?