Reputation: 1
I don't sort the values to the end in the array. Help, what should I do? I've tried several ways, all with the same result.
array2 = needItems.FindAll(x => x.nameTypeProduct == "Колесо").ToArray();
//initialy //11145 | 10161| 14804 | 11509 | 11959 | | 3445 | 8439 |13892
var k = array2.ToArray().OrderBy(x => x.cost);
//result //10161 | 11145 | 11509 | 11959 | 13892 | 14804 | 3445 | 8439
Upvotes: 0
Views: 46
Reputation: 174505
The resulting sequence:
10161 | 11145 | 11509 | 11959 | 13892 | 14804 | 3445 | 8439
is sorted, but it's alphabetically, because the ranking value resolved by x => x.cost
is a string.
Change it so that it resolves to an integral type and it'll sort them by numerical value instead:
var k = array2.ToArray().OrderBy(x => int.TryParse(x.cost, out int cost) ? cost : int.MaxValue);
Upvotes: 1