缩短属性.设置.默认为较小的变量

  • 本文关键字:变量 默认 属性 设置 c#
  • 更新时间 :
  • 英文 :


(在作为重复项关闭之前,请阅读:我已经浏览了类似的主题,但没有足够的解释代码应该在哪里执行)

我想在加载表单时将Properties.Settings.Default设置为较短的变量。

    public Object xx;
    public Form1()
    {
        InitializeComponent();
        xx = Properties.Settings.Default;
    }
    private void button1_Click(object sender, EventArgs e)
    {
       MessageBox.Show(xx.something_name);
    }

我后来在打电话给xx.something_name时收到错误... 如何成功地做到这一点?

只需使用正确的类型存储xx,而不是Object

private Properties.Settings xx;
public Form1()
{
    InitializeComponent();
    xx = Properties.Settings.Default;
}

在分配给Object时出现错误。制作类型 Properties.Settingsxx

public Properties.Settings xx;
public Form1()
{
    InitializeComponent();
    xx = Properties.Settings.Default;
}

最新更新