c# - Sort ArrayList with custom comparison -
i trying sort arraylist
using c#. when arraylist
contains comparable objects, possible sort using list.sort()
need sort arraylist
contains non-comparable objects. example, let's object ring
, has attribute property price
. need sort arraylist
price order. if is possible select ascending or descending more helpful. thank you!
blockquote
arratdmon = **(arraylist)**hashtb[unixmon];
if (arratdmon != null) moncount = arratdmon.count;
int[] arraymax = { moncount, tuecount, wedcount, thucount, fricount };
int maxvalue = arraymax.max();
kidattendance valmon = null; string montagname = string.empty;
blockquote
above array list sorted self.
you can implementing icomparer interface:-
public class ring : icomparer { public decimal price { get; set; } public int compare(object x, object y) { return ((ring)x).price.compareto(((ring)y).price); } }
working fiddle.
Comments
Post a Comment