Sorting of IPs in C# -
this question has answer here:
- how sort list of ip addresses using c# 3 answers
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
Post a Comment