'The array is not sorted to the end, how can this be done?
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
Solution 1:[1]
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);
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
