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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T18:07:03+00:00 2026-06-16T18:07:03+00:00

I am presently sorting a C# list using the ‘CompareTo’ method in the object

  • 0

I am presently sorting a C# list using the ‘CompareTo’ method in the object type contained in the list. I want to sort ascendingly all items by their WBS (Work Breakdown Structure) and I can manage this very well using the following code:

        public int CompareTo(DisplayItemsEntity other)
        {
            string[] instanceWbsArray = this.WBS.Split('.');
            string[] otherWbsArray = other.WBS.Split('.');

            int result = 0;

            for (int i = 0; i < maxLenght; i++)
            {
                if (instanceWbsArray[i].Equals(otherWbsArray[i]))
                {
                    continue;
                }
                else
                {    
                    result = Int32.Parse(instanceWbsArray[i]).CompareTo(Int32.Parse(otherWbsArray[i]));
                    break;
                }
            }
            return result;
        }

Now, I would like to be able to sort considering more than one parameter, as in the project name alphabetically, before considering the second which would be the WBS. How can I do this?

  • 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-16T18:07:05+00:00Added an answer on June 16, 2026 at 6:07 pm

    I don’t know the details of your class, so I’ll provide an example using a list of strings and LINQ. OrderBy will order the strings alphabetically, ThenBy will order them by their lengths afterwards. You can adapt this sample to your needs easily enough.

    var list = new List<string>
    {
        "Foo",
        "Bar",
        "Foobar"
    };
    var sortedList = list.OrderBy(i => i).
        ThenBy(i => i.Length).
        ToList();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am presently developing a web service using Ruby on Rails. I wish to
I have found an extension method that handles sorting and paging for LINQ .
I want to disable sorting of source_element .how can i do so? function dropMembers(){
presently i am working on a search application using solrcloud. I have tested many
I am presently trying to construct an OBB (Oriented Bounding Box) using the source
Is there a way to sort the initial data displayed on UI using tr:table
I'm toying with using server side sorting in my OpenLDAP server. However as I
Possible Duplicate: List of dictionaries, eliminating duplicates of one key, sorting by another Does
I am presently working on jquery mobile web app, I want to implement the
This is what I have presently: Here's my code so far: <style type=text/css> .main

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.