
why is that ? how can I fix it ?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
There is nothing to fix here.
Any()will iterate the enumeration but stop after the first element (after which it returns true).Multiple enumerations are mainly a problem in two cases:
Performance: Generally you want to avoid multiple iterations if you
can, because it is slower. This does not apply here since
Any()willjust confirm there is at least one element and is a required check for you. Also you are not accessing any remote/external resources, just an in-memory sequence.
Enumerations that cannot be iterated over more than once: E.g.
receiving items from a network etc. – also does not apply here.
As a non Linq version that only needs to iterate once you could do the following:
But, as noted, in your case it does not make a difference, and I would go with the version that is more readable to you.