代码运行时未设置变量值。代码如下

问题描述 投票:0回答:1

随后的代码中存在问题。

我无法理解为什么WorkshopIsPainted总是null,尽管workshop.Paintedtruefalse

public partial class Form1 : Form  
{  
    public bool?  WorkshopIsPainted;

    public Form1()
    { 
        InitializeComponent();
    }     

    private void timer4_Tick(object sender, EventArgs e)
    {
        if (!workshop.painted)
        {
            WorkshopIsPainted = workshop.Painted;
        }
        else return;
    }
}
c# variables null set
1个回答
0
投票

将代码更改为

private void timer4_Tick(object sender, EventArgs e)
{
  WorkshopIsPainted = workshop.Painted;
  return;
}
© www.soinside.com 2019 - 2024. All rights reserved.