c# - How can I order this simple .NET list by two properties? -


Looking at the list of

location 's, I need 2 ordering steps.

  1. Order Location type ascending
  2. The type of order for each location is the result of the name ascending order.

Sample data:

  location type | name 2 | tempstowe lower 2 | tempstowe 1 | melbourne Expected Result:  

  locations .Sort ((x, y) = & gt; {Int delta = x.LocationType.CompareTo (y.LocationType); If (delta == 0) delta = string Compar (x.Name, y.Name); Return delta;});  

Alternatively:

  var results = places. Orderbay (x = & gt; x.LocationType). Then (x = & x; x.Name);  

or in the LINQ syntax (compiled for the same thing):

  var results = loc.LocationType, loc.Name from place of location Choose ;  

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? -