比如说,我要把192.168.0.1---192.168.10.254这个范围的IP都放到一个数组中,要怎么表示呢?

解决方案 »

  1.   

    List<IPAddress> ipList = new List<IPAddress>();
    byte[] ipBytes = new byte[4]{192,168,0,0};
    for (int i = 0; i <= 10; i++)
    {
      ipBytes[2] = (byte)i;
      for (int j = 1; j <= 254; j++)
      {
        ipBytes[3] = (byte)j;
        ipList.Add(new IPAddress(ipBytes));
      }
    }
    //集合ipList就存放了192.168.0.1---192.168.10.254范围内的所有IPAddress
      

  2.   

    楼上的老兄啊,这样到了后ipList里面的值要怎么输出呢?
      

  3.   


    foreach(IPAddress ip in ipList)
    {
       Console.WriteLine(ip.ToString());
    }