无法在数组中显示结果

Cant show result in array

我是编程界的新手,第一次尝试使用 WPF 开发这个小应用程序,但我无法从标签中的数组“打印”我的结果。

public partial class MainWindow : Window
{
    Stopwatch clock = new Stopwatch();
    DispatcherTimer tick = new DispatcherTimer();


    public int I = 0;
    public string[] temporaryResult = new string[5];
    public bool start = false;
    public MainWindow()
    {
        InitializeComponent();
        updates();
    }

    private void updates()
    {
        tick.Start();
        tick.Tick += Tick;
    }

    private void Tick(object? sender, EventArgs e)
    {
        Display.Content = Math.Round(clock.Elapsed.TotalMilliseconds, 0);
        test.Content = temporaryResult[I];
    }

    private void Start_Click(object sender, RoutedEventArgs e)
    {
        if (!start)
        {
            clock.Reset();
            clock.Start();
            start = true;
        }
        else
        {
            clock.Stop();
            start = false;
            temporaryResult[I] = clock.Elapsed.TotalMilliseconds.ToString();
            I++;
            Debug.Print(temporaryResult[1]);
        }
    }
}

在方法 tick 中,我尝试用

显示我的结果

test.Content = temporaryResult[I];

没用。但是当我使用

test.Content = temporaryResult[0];

它至少有效一次。

感谢您帮助 Xerillio!

You are incrementing I (I++) after you insert a value at temporaryResult[I] so I points to an empty index.