How to sort list of Ip Addresses using c#

前端 未结 4 950
抹茶落季
抹茶落季 2020-12-01 05:43

I\'ve a list of IP addresses as follows

192.168.1.5
69.52.220.44
10.152.16.23
192.168.3.10
192.168.1.4
192.168.2.1

I\'m looking for such a

4条回答
  •  星月不相逢
    2020-12-01 06:15

    You can convert each IP address into an integer like so ...

    69.52.220.44 =>
    
    69 * 255 * 255 * 255 +
    52 * 255 * 255 +
    220 * 255 +
    44
    

    Then sort by the integer representation.

提交回复
热议问题