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 9215117
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:07:55+00:00 2026-06-18T02:07:55+00:00

To simplify my question, I’ll will give an example. Say I have a list

  • 0

To simplify my question, I’ll will give an example.
Say I have a list of objects containing a datetime and an integer attribute.
I’m ordering my list items first by the datetime field then by the integer attribute.

Item #   Date Value  Int Value
  1      2012-01-01     0
  2      2012-01-01     4
  3      2012-01-01     6
  4      2012-01-01     13

Say I have those 4 items in my list (un-ordered at first, above is how I want it to be in the end).

I’m ordering them simply by:

myList = myList.OrderBy(v=>v.MyDateValue).ThenBy(v=>v.MyIntValue).ToList();

After executing the line above, it ends up like below :

Item #   Date Value  Int Value
  1      2012-01-01     0
  4      2012-01-01     13
  2      2012-01-01     4
  3      2012-01-01     6

At first I thought it interprets my int value as a string perhaps (probably not a logical statement, just been futzing with this for quite some time) then I changed my int values to 10,11,12,13 but the result was still the same.

Any idea why this doesn’t work ? Or what I’m doing wrong?

  • 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-06-18T02:07:56+00:00Added an answer on June 18, 2026 at 2:07 am

    Solution: change your key selector to v => v.DateValue.Date, if you’re not interested in the time.

    I couldn’t duplicate the behavior you described. The following works as expected:

        private class Foo
        {
            public DateTime Date { get; set; }
            public int Id { get; set; }
        }
    
        static void Main(string[] args)
        {
            var myList = new List<Foo>
                             {
                                 new Foo {Date = new DateTime(2012, 01, 01), Id = 12},
                                 new Foo {Date = new DateTime(2012, 01, 01), Id = 1},
                                 new Foo {Date = new DateTime(2012, 01, 03), Id = 7},
                                 new Foo {Date = new DateTime(2012, 01, 01), Id = 4},
                             };
    
            var newList = myList.OrderBy(v => v.Date).ThenBy(v => v.Id).ToList();
            foreach (var f in newList)
            {
                Console.WriteLine("{0}, {1}", f.Date, f.Id);
            }
    
            Console.ReadLine();
        }
    

    Output item order is 1, 4, 12, and 7. (7 is last because its date is later.)

    I suspect that you have DateTime values whose Time is not 0.

    Verify that by changing your key selector to v => v.DateValue.Date.

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

Sidebar

Related Questions

To simplify my question, let's say I have the following script: var sPath =
To simplify the scenario, let's say we have a list of People with FirstName
I'm developing a REST api. To simplify my question, I have an API that
I've tried to simplify for the purposes of asking this question. Hopefully, this will
so i have 4 divs (i actually have many more but this will simplify
To simplify my question using the statement below, how can I have my javascript
Quick question/clarification required here. I have a DB table that will quite possibly have
I tried to simplify my question to a basic example I wrote down below,
I have a problem interoperating between system.drawing and WPF. To simplify this question I've
I'm going to simplify this question. I have a jqgrid instance which posts an

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.