【发布时间】:2014-03-18 18:20:12
【问题描述】:
为什么会出现IndexOutOfRange 异常?
string[] achCheckStr = File.ReadAllLines("achievements.txt");
if (achCheckStr[0] == ach1_StillBurning) // this is where the exception occurs
{
setAchievements(1);
}
if (achCheckStr[1] == ach2_Faster)
{
setAchievements(2);
}
【问题讨论】:
-
您是否验证过您实际上是在使用调试器获取文件的内容?
-
在 i(achCheckStr[0] == .... 之前添加:if(achCheckStr != null)
-
添加断点,验证
achCheckStr有数据...
标签: c# arrays exception exception-handling file.readalllines