【发布时间】:2012-06-02 23:52:38
【问题描述】:
所以我有这几行代码:
string[] newData = File.ReadAllLines(fileName)
int length = newData.Length;
for (int i = 0; i < length; i++)
{
if (Condition)
{
//do something with the first line
}
else
{
//restart the for loop BUT skip first line and start reading from the second
}
}
我尝试过使用 goto,但如您所见,如果我再次启动 for 循环,它将从第一行开始。
那么如何重新开始循环并更改起始行(从数组中获取不同的键)?
【问题讨论】:
-
如果条件为真你只想读第一行,如果条件为假则只从第2行读到最后?
-
还要注意你的
i <= newData.Length应该是<。 -
如果是真的,我在第一行做一些工作,然后是第二行等等。