“System.ArgumentOutOfRangeException”类型的未经处理的异常在 mscorlib.dll 中发生 其他信息: 索引超出范围

GYerik 2016-04-20 12:04:33
 //当前要测试的单词数组下标
public static int iCurTestWordIndex;
public static string strLocalHAddr;
public static IPEndPoint SearchServeripEP;
public static int sendDataLen;
public static byte[] udpRecvDataBuf;
public static byte[] udpDataSendBuf;
public static ManualResetEvent mrEventGotServer;
public static ManualResetEvent mrEventTermiThread;
public static void workThread()
{
#region 获取本地可用IP地址
strLocalHAddr = null;
IPHostEntry ipHostInfo = Dns.GetHostEntry(Dns.GetHostName());
//检测可用网卡网关值,确定是否可用
NetworkInterface[] NetWorkInterfaces = NetworkInterface.GetAllNetworkInterfaces();
foreach(NetworkInterface NetworkIntf in NetWorkInterfaces)
{
IPInterfaceProperties IpInterPro = NetworkIntf.GetIPProperties();
UnicastIPAddressInformationCollection uniIPAInfoCol = IpInterPro.UnicastAddresses;
foreach(UnicastIPAddressInformation UniCIPAInfo in uniIPAInfoCol)
{
if((UniCIPAInfo.Address.AddressFamily==AddressFamily.InterNetwork)
&& (UniCIPAInfo.IPv4Mask!=null))
{
if(IpInterPro.GatewayAddresses[0].Address.ToString().CompareTo("0.0.0.0")!=0)
{
strLocalHAddr = UniCIPAInfo.Address.ToString();
break;
}
}
}
}


调试的时候出现“System.ArgumentOutOfRangeException”类型的未经处理的异常在 mscorlib.dll 中发生

其他信息: 索引超出范围。必须为非负值并小于集合大小。
...全文
1404 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
exception92 2019-04-22
  • 打赏
  • 举报
回复
引用 4 楼 chic is cool 的回复:
引用 3 楼 exception92 的回复:
Gatewayaddresses 中不存在数据。
那不存在数据的话该肿么办呢
想办法让它存在数据,数据有没有是你控制的。
chic is cool 2019-04-19
  • 打赏
  • 举报
回复
引用 3 楼 exception92 的回复:
Gatewayaddresses 中不存在数据。
那不存在数据的话该肿么办呢
  • 打赏
  • 举报
回复
IpInterPro.GatewayAddresses的count为0呗。 所以[0]也超出索引范围
exception92 2016-04-20
  • 打赏
  • 举报
回复
Gatewayaddresses 中不存在数据。
GYerik 2016-04-20
  • 打赏
  • 举报
回复

110,549

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧