I have a List<MyObj>
with the class MyObj : IComparable
. I wrote the method CompareTo
in the MyObj
class per the IComparable
interface, but when I use the List<MyObj>.Contains(myObjInstance)
it returns false
when it should be true
.
I'm not sure I'm understanding how I need to proceed to make sure the List
uses my custom comparison method when calling then Contains
function.
Here is my compareTo implementation:
#region IComparable Members
public int CompareTo(object obj)
{
MyObj myObj = (MyObj)obj;
return String.Compare(this.Symbol, myObj.Symbol, true);
}
#endregion
Note the Symbol property is a string.
To clarify I've put a stopping point in that compareTo method and it doesn't even go in there.
Anyone has ever tried that?
Thanks.