Similar to this question but rephrased for Linq:
You can use Enumerable<T>.Any()
to test if the enumerable contains data. But what's the efficient way to test if the enumerable contains a single value (i.e. Enumerable<T>.Count() == 1
) or greater than a single value (i.e. Enumerable<T>.Count() > 1
) without using an expensive count operation?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…