-1

I have to create a simplistic C# windows application that initializes a boolean array of size 10 to false at the beginning of the program. Then as input is added it slowly changes each array indent to true. I can't figure out where to put this. I can't put it in the enterButton event as that would initialize the entire array to "false" each time the button is clicked, but I need it to hold its last spot.

 bool[] assignedSeat = new bool[10];
 for (int i = 0; i < assignedSeat.Length; i++)
            {
                assignedSeat[i] = false;
            }
  • 1
    You'd put `assignedSeat` in the class-level scope of the form where the button exists. Not inside the "button click" event scope. – Andy Feb 06 '21 at 06:36

1 Answers1

0

use this

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++;
    }
}
Meysam Asadi
  • 6,438
  • 3
  • 7
  • 17