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;
}
Output: