I need a C# method to remove duplicates from a List<T> using a custom comparison operation. In .NET 4. Is there one or do I have to write it myself?
I need a C# method to remove duplicates from a List<T> using a custom
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.
Assuming your comparison operation is
IEqualityComparer<T>or can be converted to it, you’re fine with LINQ:Obviously that creates a new list rather than removing elements from the old one, but in most cases that’s okay. You could always completely replace the contents of the old list with the new list afterwards if not…