(在作为重复项关闭之前,请阅读:我已经浏览了类似的主题,但没有足够的解释代码应该在哪里执行)
我想在加载表单时将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.Settings
的xx
。
public Properties.Settings xx;
public Form1()
{
InitializeComponent();
xx = Properties.Settings.Default;
}