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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:13:57+00:00 2026-05-29T10:13:57+00:00

I am trying to sort a bunch of objects that have sort order, however

  • 0

I am trying to sort a bunch of objects that have sort order, however some fields have been initialized to 0, so I want to first display all users/objects that have a sort order (in the actual correct order) then display then others e.g.

my list

{id:4,name:"Tom", sortoder:0}
{id:14,name:"Bee", sortoder:0}
{id:401,name:"Mike", sortoder:1}
{id:13582,name:"Monty", sortoder:2}
{id:55,name:"Charlie", sortoder:0}
{id:9,name:"Khan", sortoder:9}

        var fields = GetFields(myobject) //get fields (not really relevant)
                     .OrderBy(x => x.sortoder > 0) //this is where I am stuck on
                     .ToList();

My lists are all dislaying users with 0 at the top then those that have a sort order

  • 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-29T10:13:58+00:00Added an answer on May 29, 2026 at 10:13 am

    Either use ThenBy to apply a second ordering after the first:

    var fields = GetFields(myobject)
        .OrderByDescending(x => x.SortOrder > 0)
        .ThenBy(x => x.SortOrder)
        .ToList();
    

    Or you could use a conditional expression to replace the value 0 with int.MaxValue (assuming that int.MaxValue does not occur as a legitimate SortOrder):

    var fields = GetFields(myobject)
        .OrderBy(x => x.SortOrder == 0 ? int.MaxValue : x.SortOrder)
        .ToList();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to sort a bunch of data such that that the size of
Trying to sort this array of objects according to (1) depth and (2) weight,
I am trying to sort large inputs in the fastest way in ascending order.
I'm trying to sort a list of CLLocationDistance values by closest distance (ascending order).
I'm trying to sort a multidimensional array in objective-c i know that i can
I'm trying to sort a list (part of a class) in descending order containing
I'm trying to sort any array with array_multisort() and everything is working great. However,
Problem I have a YQL query result that I'm trying to get converted and
I'm trying to sort a list of objects according to my criteria. Here is
I'm trying to sort a bunch of products by customer ratings using a 5

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.