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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:40:00+00:00 2026-05-26T23:40:00+00:00

I have a list of fields which a user can sort using jquery. I

  • 0

I have a list of fields which a user can sort using jquery. I save these updated fields in the database. The same fields can be added and removed from the report, so in some cases I will have field1, field55, field 3. The fields can appear in a random order (based on where it appears in the report).

I am trying to sort a list where in most cases the field will have a value but it can also be 0.

var list = Dictionary<string,int>(); //loaded from the client side, in-memory

I have a list where I use the method list.orderby(x=> x.Value); This will sort fields in the correct order, however I want to get the remaining fields whos order = 0, and append to the end of the list with the greatest number in the list.

e.g. the highest number in the list is 78, I have 4 fields that have the prop Order = 0, these fields should be 79,80,81,82 respectively.

Something like this may work, but I am getting a collection modified error:

        var max = list.Max(x => x.Value);

        foreach (var item in list.Where(x => x.Value == 0))
        {
            list[item.Key] = ++max;
        }
  • 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-26T23:40:00+00:00Added an answer on May 26, 2026 at 11:40 pm
    var list = new Dictionary<string, int>
        {
            {"Banana", 123},
            {"Apple", 234},
            {"Orange", 34},
            {"Pear", 4},
            {"Elephant", 99},
            {"UnOrderedItem1", 0},
            {"UnOrderedItem2", 0},
            {"UnOrderedItem3", 0},
            {"UnOrderedItem4", 0},
        };
    
    int nextValue = list.Max(x => x.Value) + 1;
    var elementsWithZero = (from l in list where l.Value == 0 select l)
        .ToList();
    
    foreach (var item in elementsWithZero)
    {
        list[item.Key] = nextValue++;
    }
    
    var sortedList = (from l in list select l)
        .OrderBy(x => x.Value);
    
    foreach (var item in sortedList)
    {
        Console.WriteLine("{0}: {1}", item.Value, item.Key);
    }
    

    Output:

    4: Pear
    34: Orange
    99: Elephant
    123: Banana
    234: Apple
    235: UnOrderedItem1
    236: UnOrderedItem2
    237: UnOrderedItem3
    238: UnOrderedItem4
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a form and a sortable() list where a user can drag from
i have a select dropdown list which has 4-5 fields. As soon as a
I have a list of custom objects which I have added to a ListBox
I have a form in which the user can either select from a pre-existing
The problem I have a list of tasks with which a user is greeted
I have a list of fields/columns that comprises of Sharepoint specific fields/columns, my own
In a C# 2.0 I have a list of fields and a list of
I have a list I've built in Sharepoint, where one of the fields is
I have a field object and I create a list of fields: class Field
I have filled List<Object1> Object 1 contain 2 fields (int id & string name)

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.