c# - Sort List with duplicate keys by custom comparer -


i have list inputcoll of type myvalue many duplicate keys:

myvalue1.id=100; myvalue2.id=100; ...etc 

and have custom comparer compare 2 myvalue elements id:

inputcoll.sort(myvaluecomparer); 

what 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;     } } 

unless equality comparer not implemented badly, solution should work.

but suggest easier approach, using linq:

inputcol = inputcol.orderby(o => o.id).tolist(); 

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -