I have the List
inputColl
of type MyValue
with many duplicate keys:
myValue1.Id=100;
myValue2.Id=100;
...etc
And I have custom comparer to compare two MyValue
elements by Id
:
inputColl.Sort(myValueComparer);
What am I doing wrong?
Comparer:
public class MyValueComparerById : IComparer<MyValue>
{
public int Compare(MyValue x, MyValue y)
{
if (x.Id == y.Id)
return 0;
else if (x.Id > y.Id)
return -1;
else if (x.Id < y.Id)
return 1;
return 0;
}
}