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

  • Home
  • SEARCH
  • 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 925185
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T19:28:52+00:00 2026-05-15T19:28:52+00:00

i have a collection of objects and i am looking to sort by a

  • 0

i have a collection of objects and i am looking to sort by a property that is a DateTime?

  list.OrderBy(r => r.Milestone)

where milestone is a:

  public DateTime? Milestone { get; set; }

it seems to put all of the items with novalue at the top of the sort. Is there anyway to sort by date but put the empty items at the bottom of the list. (i dont care about the ordering of the empty ones of course)

So if i have 4 items:

  1. 1/1/2001
  2. 1/1/2002
  3. [No DateTime]
  4. 1/1/2004

i would want to order the list 1,2,4,3

  • 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-15T19:28:53+00:00Added an answer on May 15, 2026 at 7:28 pm

    One easy option:

    list.OrderBy(r => r.Milestone ?? DateTime.MaxValue)
    

    That won’t work nicely if there are values with a mileston of DateTime.MaxValue, of course.

    Recently there was a related question about implementing IComparer<T> to put nulls at the end, but I can’t find it now… the above is definitely the simplest solution though, if you won’t be using MaxValue for anything else.

    Alternatively:

    list.OrderBy(r => !r.Milestone.HasValue)
        .ThenBy(r => r.Milestone)
    

    will order all the values that do have a milestone first, and then the ones which don’t. That way you it will work even if some milestones use DateTime.MaxValue. It’s a little more obscure to my eyes, but you may prefer it.

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

Sidebar

Related Questions

I'm looking to have a collection of objects that implement a certain interface, but
I have a list/collection of objects that may or may not have the same
If I have a collection of objects: public class Party { LinkedList<Guy> partyList =
C#: I have a collection of objects . T has 2 properties. Property A
I have an observable collection of objects that I'd like to display on the
I have a collection of objects that's constantly changing, and I want to display
I have a collection of objects that I would like to partition into two
I have an collection of iQueryable objects. Looking through intellisense i see 'GetElementAt(int)' but
I have a collection of domain objects that I need to convert into another
I have an unsorted Collection of objects [that are comparable], is it possible to

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.