Is there any great way to ensure multiple collections have the same item count using LINQ ?
Share
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.
Try this:
or:
It works by finding checking the length of each collection and keeping track of unique values. Having one distinct count is OK, but if there are two (or more) distinct counts then all the collections aren’t the same length so the result is false.
Update: If the collections have different types you can use a non-generic interface as demonstrated in this answer.