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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T21:08:51+00:00 2026-06-14T21:08:51+00:00

I want to sort already sorted list in this manner. Already Sorted List =

  • 0

I want to sort already sorted list in this manner.

Already Sorted List =

Ali-23423423423
Ali-234234
Ali-234234255
Bali-36365356
Bali-32326546456
Bali-361111
Tali1-234234
Tali2-2342342
Tali3-23424

I am trying to find a query so that I can sort it like this

Ali-12315254
Bali-23346363
Tali-242452345
Ali-2342134134
Bali-234234234
Tali-242342

and So On.

I made a loop for the job but it is very slow and some what problematic as-well. Is there any solution?

while (List1.Count+10 < List.Count) 
{ 
    i++; 
    if (List.ElementAt(i).Remove(List.ElementAt(i).IndexOf('-')) == List1.ElementAt(i + 1).Remove(List1.ElementAt(i + 1).IndexOf('-'))) 
    { 
        String Element = List.ElementAt(i); 
        List.RemoveAt(i); 
        List.Add(Element); 
        i--; 
    } 
    else 
    { 
        List1.Add(List.ElementAt(i)); 
    } 
} 
List = List1; 

is the not so good way around I come up with

  • 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-14T21:08:52+00:00Added an answer on June 14, 2026 at 9:08 pm

    This query will give you unique items by name

    var query = from s in list                        
                let name = s.Split('-')[0]
                group s by name into g
                orderby g.Key // don't sure if you need ordering
                select g.First();
    

    UPDATE I think this code does exactly what you want – only first occurrence of every name is selected first, then second occurrences are selected, etc

    List<string> sortedList = new List<string>();
    
    while (list.Any())
    {
        var query = list.GroupBy(s => s.Split('-')[0], (k,g) => g.First()).ToList();
        // list.RemoveAll(s => query.Contains(s));
        query.ForEach(s => list.Remove(s)); // I think this is more effective
        sortedList.AddRange(query);
    }
    

    Output for your sample data is:

    Ali-23423423423 // first loop
    Bali-36365356
    Tali1-234234
    Tali2-2342342
    Tali3-23424
    Ali-234234 // second loop
    Bali-32326546456
    Ali-234234255 // third loop
    Bali-361111
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to sort list items by their priority, which the user types in,
I want to sort a list of integer values, but before sorting them I
I have a list of userprofiles that I want to be able to sort
I want to sort a list by each item's digit. Example: myCmpItem = '511'
I want to sort a 2-dimensional String array like this xx, text 1 aa,
I want to sort the items inside column of ListView, i already made it,
i have a list of country names. Now i want to sort them alphabeticly,
I have this array, which is already sorted by 'name' ASC. array 0 =>
I want to sort a mutable array by date. My array contains several dict
I want to sort the items that have been previously selected with checkboxes. If

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.