How can I efficiently determine if an IEnumerable has more than one element?

You can test this in many ways by combining the extension methods in System.Linq… Two simple examples are below:

bool twoOrMore = enumerable.Skip(1).Any();
bool twoOrMoreOther = enumerable.Take(2).Count() == 2;

I prefer the first one since a common way to check whether Count() >= 1 is with Any() and therefore I find it more readable.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)