dimanche 18 mars 2018

For loop never satisfies a condition WPF

In the current page (which is contained inside a frame inside MainWindow) I have this happen when I click a button:

    for (int i = 0; i < mw.pizzas.Length + 1; i++)
    {
        if (i == 10)
        {
            MessageBoxResult result = MessageBox.Show("You can't order more than 10 pizzas");
            break;
        }
        if (mw.pizzas[i] == null)
        {
            mw.pizzas[i] = pizza;
            break;
        }
    }
    NavigationService.Content = new AnotherPage();

The mw.pizzas string array contains 10 (I think undefined) variables. I have defined it in MainWindow:

public string[] pizzas = new string[10];

I have defined it on the current page, like so:

MainWindow mw = new MainWindow();

This loop increments by defining these 10 slots with the contents of the variable "pizza". When all of the indexes of the array are defined, a message should pop up. However, this message never shows up. What am I doing wrong here?

Aucun commentaire:

Enregistrer un commentaire