小编Kir*_*rev的帖子

c#restart for循环

所以我有这几行代码:

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循环,它将从第一行开始.

那么如何重新启动循环并更改起始行(从数组中获取不同的键)?

c# for-loop restart

6
推荐指数
2
解决办法
1万
查看次数

C#从另一个类获取textBox值

假设我有一个名为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#中很新,并且不能让这个东西起作用.

c# textbox

3
推荐指数
2
解决办法
3万
查看次数

标签 统计

c# ×2

for-loop ×1

restart ×1

textbox ×1