Recommand · May 27, 2021 0

How to sort numeric strings based on length and value

Maybe the question itself is not properly worded, however I will try to explain what I’m trying to accomplish.

Basically, I have a list of numerical strings that looks like this:
var channelIds = new List<string>{"11","12","13,"14,"15","16","17","18","19","21","22","23","24","110"}

The way I produce this list of strings is by joining two properties called Row and Column, so technically value 110 is Row 1, Column 10.

The order that I’m trying to produce is this:

11,
12,
13,
14,
15,
16,
17,
18,
19,
110,
21,
22,
23,
24

Regular .OrderBy() will return 11, 110, 12, 13 and so forth. I have to perform this sort after I do ${Row}{Column} since there is some additional logic that is being performed. I’ve also attempted explicitly casting to int, however that also does not help.