C# How to sort a list that is already in memory

1 comments
	protected class ColumnSorter : IComparer { public int Compare(LstHeadObj x, LstHeadObj y) { var result = 0; if (x.OrderDate_ORDT > y.OrderDate_ORDT) result = -1; return result; } } ... //sort list by desc date IComparer desc = new ColumnSorter() ; headers.Sort(desc); 


if (headers.Count > 0) {

	for (var sc = 0; sc < headers.Count-1; sc++) {
	var header = headers[sc];
	if (header.OrderDate_ORDT 

also another option


				List<SelMtrlTransObj> filtered = smt.Out.FindAll(i => Convert.ToInt32(i.Status_STAT) == 40 && i.OrderCategory_ORCA == "251");
				if (filtered.Count > 0) {
					// get the first planning date
					// sort by date 
					filtered.Sort((item1, item2) => item1.PlanningDate_PLDT.Value.CompareTo(item2.PlanningDate_PLDT.Value));
					DateTime? firstPlanningDate = filtered[0].PlanningDate_PLDT;



Comments

sorry, format is stuffed
Posted by Jeremy Nicholls | jeremy@beweb.co.nz

youll need to pretty print it



Leave a Comment