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

The Archive Base Latest Questions

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

I am pretty confused with sorting out list in C#, I have gone through

  • 0

I am pretty confused with sorting out list in C#, I have gone through different tutorials for sorting e.g. sorting using list (sort method) or use IComparable but nothing actually helped me with what I want.

for example I have a list of cars,

Car Number

Car Title

and few other properties

Now Car number can be any double number or it can be Nan (null) and Car Title can never be null.

I want to sort list in a way that first it gets sorted by Car Numbers and if they are not available for a car then use its title to sort rest of cars.

so if I have something like this,

Car 1      100.0 (car number)                  BMW x6 (car name)
Car 2      (there isn't any car number)        Mercedies A class (car name)
Car 3      99.0                                Alpha Romeo
Car 4      1.2                                 Jeep
Car 5      4.1                                 Victoria Marshall 1933
Car 6      no number                           Vauxhal

Out put I want my list class to be sorted as

Car 4, Car 5, Car 3, Car 1, Car 2, Car 6

Thanks for help.

  • 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-18T09:53:55+00:00Added an answer on June 18, 2026 at 9:53 am

    try something like

    var lst = new List<Cars>()
    
    //add cars to list
    
    lst = lst.Orderby(c => c.CarNumber).ToList();
    

    you can extend it like this:

    lst = lst.Orderby(c => c.CarNumber).ThenBy(c=> c.Title).ToList();
    

    Or

    You implement the IComparable so it will sort the way you want:

    public class Car : IComparable<Car> 
    { 
        public string Number { get; set; } 
    
        public int CompareTo(Car obj) 
        { 
            return obj.Number.CompareTo(Number); 
        } 
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm pretty confused with the use of the select method. This is how I
I'm pretty confused. I have a point: x= -12669114.702301 y= 5561132.6760608 That I got
Ok, so fb_graph looks pretty simple to use but Im kinda confused as how
i have readed many topic but i'm pretty confused. it seems that: if ([[UIScreen
I am new to LINQ, so I am pretty confused here. I have a
Learning C here, and I'm pretty confused on how to use function prototypes. I'm
I am a Java beginner and pretty confused with this. How is System.out.println(4*2147483647) equal
Pretty confused newbie here: I have a class, this class is adding columns to
I'm pretty confused on how to go about this. Say I have two columns
I have to admit that I am pretty confused how annotations work in java

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.