Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 763715
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T16:36:28+00:00 2026-05-14T16:36:28+00:00

I have a fairly complex scenario and I need to ensure items I have

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T16:36:28+00:00Added an answer on May 14, 2026 at 4:36 pm

    It sounds like you need to get canonicalized date sorting even though your date is represented as a string, yes? Well, you can use LINQ’s OrderBy operator, but you will have to parse the string into a date to achieve correct results:

    items = items.OrderBy(item => DateTime.Parse(item.subLevelItem.DeliveryTime))
                 .ToList(); 
    

    Update:

    I’ve added this in for completeness – a real 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, it’s 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() );
    

    Be aware that most Sort() methods in the .NET framework accept an IComparer or IComparer<T> which allows you to redefine the comparison semantics for any type. Normally, you just use Comparer<T>.Default – or use an overload that essentially supplies this for you.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some fairly complex requirements for a SOLR search that I need to
I have a fairly complex query that looks something like this: create table Items(SomeOtherTableID
I have a fairly complex express based web application that is split up into
I have a fairly complex scenario that I try to port to Windows 8
I have a fairly complex view that has multiple forms, lots of validations on
I have a web application I've developed that has a fairly complex save routine.
I have a web page that I use to update a fairly complex data
I have a fairly complex business application written in ASP.NET that is deployed on
I have a fairly complex model needing to be validated, the problem is that
I have a fairly complex user drawn control that is double buffered. Works very

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.