Sorting of IPs in C# -


this question has answer here:

i have list of valid ip's a

list<string> ip = new list<string>() 

for instance have:

192.168.1.54

192.168.1.95

192.168.1.22

192.168.1.26

192.168.1.4

192.168.1.11

192.168.1.103

how can sort list appear sorted last numerical value? (all ip's within same subnet first 3 octets won't matter)

192.168.1.4

192.168.1.11

192.168.1.22

192.168.1.26

192.168.1.54

192.168.1.95

192.168.1.103

any ideas?

it works list of strings too, tested it, try yourself:

list<string> unsortedips = new list<string>();         unsortedips.add("192.168.1.103");         unsortedips.add("192.168.1.95");         unsortedips.add("192.168.1.4");         unsortedips.add("10.152.16.23");         unsortedips.add("192.168.1.1");          var sortedips = unsortedips             .select(version.parse)             .orderby(arg => arg)             .select(arg => arg.tostring())             .tolist(); 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

android - Keyboard hides my half of edit-text and button below it even in scroll view -

css - Make div keyboard-scrollable in jQuery Mobile? -