jeudi 16 septembre 2021

How to repeat elements on array with button click in Visual Studio 2019

I am making a simple math game of arithmetic operators. I want the operand to change whenever I click Next button.

This is my code. It changes the operand but stops the program when all elements of the array are used. How am I able to repeat the elements of array in a random order?

String[] operand = { "+", "-", "/", "*" };
private void btnNext_Click(object sender, EventArgs e)
{
    int i = Array.IndexOf(operand, lblOperand.Text);

    if (i >= 0)
        lblOperand.Text = operand[i + 1];
    else
        lblOperand.Text = operand[0];
} 



Aucun commentaire:

Enregistrer un commentaire