Possible Duplicate:
How to Count Duplicates in List with LINQ
Any idea how do you count a duplicate in linq. Let’s say i have a list of Student objects
where i wanna find the amount of student called ‘John’?
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.
You can use GroupBy:
Returns:
You can show the ones that have duplicates too:
Returns:
Note: You will need to change
GroupBy(x => x)depending on what yourStudentobject is of course. In this case, it’s just astring.