Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typo3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 数组更新程序_C# - Fatal编程技术网

C# 数组更新程序

C# 数组更新程序,c#,C#,我需要让我的按钮检查用户是否: 在位置文本框中输入文本 在名称文本框中输入文本 如果未输入任何内容,则会显示错误消息框并退出该过程 它还需要调用我的insertIntoArrayist()过程并将值传递给它,然后将新值插入数组列表。 然后调用我的populateActors()一 以下是我到目前为止的情况: public void () { *snip* } 目前很确定它会添加名称,但不会添加到正确的位置。。例如,如果我想在位置“1”中添加一个名称“Bob Marley”,它需要进入数

我需要让我的按钮检查用户是否:

  • 在位置文本框中输入文本
  • 在名称文本框中输入文本
如果未输入任何内容,则会显示错误消息框并退出该过程

它还需要调用我的insertIntoArrayist()过程并将值传递给它,然后将新值插入数组列表。 然后调用我的populateActors()一

以下是我到目前为止的情况:

public void ()
{
  *snip*
}
目前很确定它会添加名称,但不会添加到正确的位置。。例如,如果我想在位置“1”中添加一个名称“Bob Marley”,它需要进入数组的顶部。
代码中可能还有其他错误,因此如果您看到任何错误,请告诉我!感谢所有提示:)

在按钮单击处理程序中执行while循环是一个大问题

//This button needs to give the error if the name or position in the array are left blank//
private void btnInsert_Click(object sender, EventArgs e)
{
    // BIG PROBLEM HERE!!!!
    do
    {
        string message = "Invalid Name or Position entered.";
        MessageBox.Show(message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
    }
    while (int.Parse(txtPosition.Text == null));

    InsertIntoArrayList(actName, posNum);
    PopulateActors();
}
首次单击按钮时,如果未满足
int.Parse(txtPosition.Text==null)
条件,则会重复显示一个消息框,而不会给用户提供修复错误的机会

请尝试以下方法:

//This button needs to give the error if the name or position in the array are left blank//
private void btnInsert_Click(object sender, EventArgs e)
{
    if (int.Parse(txtPosition.Text == null)) {
        MessageBox.Show(message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
    } else {
        InsertIntoArrayList(actName, posNum);
        PopulateActors();
    }
}
而是在每次单击按钮时检查条件,让用户有机会修复问题


您的数组插入代码在我看来很好。

我可以看到各种问题,但您需要自己分析发生了什么,而不是期望每个人都为您工作。当你运行这个程序(假设它可以编译)时,它会给你你期望的输出吗?我不希望人们回答我,只是告诉我哪里出了问题,我可以自己回去编辑它,或者告诉我应该怎么做。。而不是我是怎么做的。是的,当我最初测试它时,这就是问题所在,它不断地给我错误。所以if/else看起来更合适,谢谢。