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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:09:12+00:00 2026-05-23T11:09:12+00:00

I have a List object that contains items in following type public class Item{

  • 0

I have a List object that contains items in following type

public class Item{

    public int Type; //this can be only 0 or 1
    public string Text;


}

I would like to sort the entire list by the Type first and then do another sort by Text for only items that have type is 1?

How to achieve this?

Many thanks

Ming

  • 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-23T11:09:12+00:00Added an answer on May 23, 2026 at 11:09 am

    Here’s how I’d do it.

    var ordered = list.OrderBy(i => i.Type == 0 ? "" : i.Text);
    

    This is assuming there are no empty Text strings where i == 0. If you can’t make that assumption, the following would work:

    var ordered = list.OrderBy(i => i.Type).ThenBy(i => i.Type == 0 ? "" : i.Text);
    

    By giving all items with a 0 Type the same value, you’ll leave them all in their initial order, while sorting other items by their Text value.

    On a side note, this is a code smell:

    public int Type; //this can be only 0 or 1
    

    At a glance, that sounds like it ought to be a boolean or a custom enum type. After taking a deeper look at what you’re trying to do, it sounds like maybe you’re not expecting Text to even be a legitimate value if Type is 0. If that’s the case, you should consider using class inheritance to actually differentiate one item type from another.

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

Sidebar

Related Questions

I have a list of class items List<MyClass> I have a seperate object that
I have an ASP.NET WebService that returns an object of List public class Students
I have a class that contains a list of objects. I previously had this
I have a class that contains a list of objects. What's the best way
I have a class Player that contains a list of Accessory objects. There are
I have a class that contains a static number of objects. This class needs
Lets say I have query that gets following List Item Objects with Set of
I have a 2 lists that contain BreadCrumbItem object: public BreadcrumbItem() { this.Title =
I have the following view model: Public Class MyViewModel Public Property SelectedIDs As List(Of
I have a class ShipmentsCollection that inherits ObservableCollection which contains shipment objects (entities). This

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.