Q: 要把192.168.0.1---192.168.10.254这个范围的IP都放到一个数组中,要怎么表示呢?
A:
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
Code
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