错误-System.IndexOutOfRangeException:索引超出了数组的界限
本文关键字:数组 界限 -System IndexOutOfRangeException 索引 错误 | 更新日期: 2023-09-27 18:25:19
我得到这个错误:
System.IndexOutOfRangeException: Index was outside the bounds of the array.
运行此代码时:
foreach(var row in data)
{
string strAddr = row.ADDRESS1 + "," + row.CITY + "," + row.ST;
GoogleMapsDll.GeoResponse myCoordenadas = new GoogleMapsDll.GeoResponse();
myCoordenadas = GoogleMapsDll.GoogleMaps.GetGeoCodedResults(strAddr);
string strLat = myCoordenadas.Results[0].Geometry.Location.Lat.ToString();
string strLong = myCoordenadas.Results[0].Geometry.Location.Lng.ToString();
System.Threading.Thread.Sleep(10);
}
我不知道它到底意味着什么,也不知道我该如何修复它。任何意见都将不胜感激。
它通常由x[12]等索引运算符抛出。你碰巧有:Results[0]
。所以这一定意味着数组实际上是空的,它甚至没有零索引。顺便说一句,在调试器中运行您的代码,并查看异常的确切抛出位置。