Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/302.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#Windows窗体应用程序如何一次而不是每次按钮事件发生时初始化数组_C# - Fatal编程技术网

C#Windows窗体应用程序如何一次而不是每次按钮事件发生时初始化数组

C#Windows窗体应用程序如何一次而不是每次按钮事件发生时初始化数组,c#,C#,我必须创建一个简单的C#windows应用程序,在程序开始时将大小为10的布尔数组初始化为false。然后,随着输入的添加,它会慢慢地将每个数组缩进更改为true。我不知道该把这个放在哪里。我不能将它放在enterButton事件中,因为每次单击按钮时都会将整个数组初始化为“false”,但我需要它保持最后一个位置 bool[] assignedSeat = new bool[10]; for (int i = 0; i < assignedSeat.Length; i++)

我必须创建一个简单的C#windows应用程序,在程序开始时将大小为10的布尔数组初始化为false。然后,随着输入的添加,它会慢慢地将每个数组缩进更改为true。我不知道该把这个放在哪里。我不能将它放在enterButton事件中,因为每次单击按钮时都会将整个数组初始化为“false”,但我需要它保持最后一个位置

 bool[] assignedSeat = new bool[10];
 for (int i = 0; i < assignedSeat.Length; i++)
            {
                assignedSeat[i] = false;
            }
bool[]assignedSeat=新bool[10];
对于(int i=0;i
使用此

bool[] assignedSeat = new bool[10];
int currentIndex = 0;
public Form1()
{
    InitializeComponent();
    for (int i = 0; i < assignedSeat.Length - 1; i++)
    {
        assignedSeat[i] = false;
    }
}

private void Button_Click(object sender, EventArgs e)
{
    if(currentIndex < assignedSeat.Length)
    {
       assignedSeat[currentIndex] = true;
       currentIndex++;
    }
}
bool[]assignedSeat=新bool[10];
int currentIndex=0;
公共表格1()
{
初始化组件();
对于(int i=0;i
assignedSeat
放在按钮所在表单的类级别范围内。不在“按钮单击”事件范围内。