I am trying to use Enumerable.OrderBy to sort a list, because ultimately I want to be able to sort more than one field. At the moment, it only works if I create a new var variable to hold the presentation of the results, which means ( I think) that types should be re-mapped.
Is there a way to sort the list by more than 1 field while keeping the original List variable and types? That is, I would rather get a variable _orderedbins type List<orderedbins>
Below is what I currently have, but everything from var test = ... further seems a bit wrong.
public class orderedBins { public string Bin { get; set; } public int Order { get; set; } } List<orderedbins> _orderedbins = new List<orderedbins>(); foreach (string item in splitbins) { string[] spbinSetting = item.Split(','); bool bchecked = bool.Parse(spbinSetting[1]); int border = int.Parse(spbinSetting[2]); if (bchecked == true) { _orderedbins.Add(new orderedbins { bin = spbinSetting[0], Order = border }); } } var test =_orderedbins.OrderBy(x => x.Order); foreach (var item in test) { string f = item.Bin; int g = item.Order; }
source share