How to Sort a list for a specific case c# -


Here is a sample code where I want to get the data sorted on the total charge property as desending order.

  // from the list & lt; RateStatus & gt; SortedList = objListOrder.OrderByDescending (O => O totalworld) .Oolist ();  

I see the code below and guidance Thank you how to sort the property of total charge in Williying

  static class Program {/// & Lt; Summary & gt; Main entry point for the application /// & lt; / Summary & gt; [STAThread] Fixed Zero Main () {List & lt; Retrastats & gt; ORateCollection = New List & lt; Retrastats & gt; (); RateStatus ortestats = new ratestats (); ORateStatus.StatusMsg = "OK"; ORateStatus.ErrorMsg = "none"; ORateStatus.RateDetails.Add (// new rate-description () (currently CCD = "GBP", the total charge = 20}); oRateCollection.Add (oRateStatus); I want something like this up / down / Switch & lt; Drstats & gt; SortedList = objListOrder.OrderByDescending (o = & gt; o Kulwarld) Kolist ();}} public class Retstats {public Retstats () {rated Sex = new list & lt; rated Sex & gt; (); } Public String StatusMsg {get; set;} Public string ErrorMsg {get; set;} Public list & quot; Details & gt; Rate details { Not; set;}} public class RateDetails {public string ServiceCode {get; set;} public string ServiceName {get; set;} public string CurrentcyCode {get; set;} public double total charge {get; set;}}  

this is the way it has been sorted.

  oRateStatus.RateDetails.Sort (new RateStatusComparer ()); oRateCollection.Add (oRateStatus); public class Retstat Commander: Compare Icompier & lt; Rate Details> {Public Ent (Compare X, Rate Details Y) (if (x Total Charges) > Y Total Charge) Return -1; Otherwise if (x. Charge in-charge & lt; y total charge) return 1; And return 0; }}  

thanks

ICMPier & Lt; Retrastats & gt; .

For example, something like this:

  public squares tastes compactor: ICP player < Retrastats & gt; {Public int (rate status x, ratestatus y) {... your comparison code here}}  

and then you use the overload of list.Sort And provide your comparative like

  var s = new tariffs compairer (); ObjListOrder.Sort (c);  

See for details.


Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -