所以我有这几行代码:
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
}
}
Run Code Online (Sandbox Code Playgroud)
我已尝试使用goto,但正如您所看到的,如果我再次启动for循环,它将从第一行开始.
那么如何重新启动循环并更改起始行(从数组中获取不同的键)?
假设我有一个名为Form1的表单,其中包含textBox和button.
我想在按钮点击时从另一个类获取textBox值.我试图这样做,但它不起作用:
class Main
{
public void someMethod()
{
Form1 f1 = new Form1();
string desiredValue = f1.textBox.Text;
}
}
Run Code Online (Sandbox Code Playgroud)
请原谅我这个愚蠢的问题,但我在C#中很新,并且不能让这个东西起作用.