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

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -