C# how to sort a list without implementing IComparable manually?

Posted by JL on Stack Overflow See other posts from Stack Overflow or by JL
Published on 2010-05-05T13:47:46Z Indexed on 2010/05/05 14:48 UTC
Read the original article Hit count: 131

Filed under:

I have a fairly complex scenario and I need to ensure items I have in a list are sorted.

Firstly the items in the list are based on a struct that contains a sub struct.

For example:

public struct topLevelItem
{
 public custStruct subLevelItem;
}

public struct custStruct
{
  public string DeliveryTime;
}

Now I have a list comprised of topLevelItems for example:

var items = new List<topLevelItem>();

I need a way to sort on the DeliveryTime ASC. What also adds to the complexity is that the DeliveryTime field is a string. Since these structs are part of a reusable API, I can't modify that field to a DateTime, neither can I implement IComparable in the topLevelItem class.

Any ideas how this can be done?

Thank you

© Stack Overflow or respective owner

Related posts about c#