It looks like you need to get canonical sorting by date, even if your date is presented as a string, right? Well, you can use the LINQ OrderBy operator, but you will need to parse the string in the date to achieve the correct results:
items = items.OrderBy(item => DateTime.Parse(item.subLevelItem.DeliveryTime)) .ToList();
Update:
I added this for completeness - a true example of how I use ParseExact with invariant culture:
var returnMessagesSorted = returnMessages.OrderBy((item => DateTime.ParseExact(item.EnvelopeInfo.DeliveryTime, ISDSFunctions.GetSolutionDateTimeFormat(), CultureInfo.InvariantCulture))); return returnMessagesSorted.ToList();
You can always implement a separate IComparer class, this is not fun, but it works well:
public class TopLevelItemComparer : IComparer<topLevelItem> { public int Compare( topLevelItem x, topLevelItem y ) { return DateTime.Parse(x.subLevelItem.DeliveryTime).CompareTo( DateTime.Parse(y.subLevelItem.DeliveryTime) ); } } items.Sort( new TopLevelItemComparer() );
Remember that most Sort() methods on the .NET platform accept IComparer or IComparer<T> , which allows you to override the comparison semantics for any type. Usually you just use Comparer<T>.Default - or use an overload that essentially provides you with this.
Lbushkin
source share