I am using Contains() to identify something that NOT contain in the list. So something like,
if(!list.Contains(MyObject))
{
//do something
}
but, the whole if statement goes to true even though MyObject is already in the list.
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.
If you do not have the ability to override Equals (or if you just don’t want to), you can implement an
IEqualityComparer<T>of your object and pass that in as the second parameter to the Contains method (overload). If your object is a reference type, it would otherwise simply be comparing references instead of the contents of the object.…
In this scenario, foo2 would not be added to the list. It would without the comparer argument.