这个bug很不寻常.基本上我的代码将更改Settings.Default.Example然后保存并重新启动程序.然后在加载时,它会显示一个消息框.奇怪的是,它在表单加载时显示一个空值.
这是我的代码:
Main.cs
private void Button1_Click(object sender, EventArgs e)
{
Settings.Default.Example = "Somevalue"; //Sets a value to the settings
Settings.Default.Save(); // Save it
MessageBox.Show(Settings.Default.Example); //Confirming it has been saved
Application.Restart();
}
private void Main_Load(object sender, EventArgs e)
{
MessageBox.Show(Settings.Default.Example); // Here is the weird part, it shows empty.
}
Run Code Online (Sandbox Code Playgroud)
该MessageBox会显示"someValue中"单击时按钮,然后在重新启动的applcation和MessageBox那表明是空的.但是,再次单击该按钮重复该过程并重新启动它会显示"Somevalue" MessageBox.请帮忙!非常感谢!
我有一个名为的属性,它是通过 Visual Studio 中的属性设置窗口 A设置的值(项目 \xe2\x86\x92 属性 \xe2\x86\x92 设置)。AAA
A我可以使用此循环获取该属性的原始值。
\n如果我更改该值,也就是说NewValue,我可以使用以下代码获取新值:
Properties.Settings.Default.A\nRun Code Online (Sandbox Code Playgroud)\n\n但是,在循环内,我不知道如何在不使用语法的情况下获取当前属性值:
\n\nProperties.Settings.Default.VariableName\nRun Code Online (Sandbox Code Playgroud)\n\n例如:
\n\nProperties.Settings.Default.A= "NewValue";\nProperties.Settings.Default.Save();\nforeach (SettingsProperty _currentProperty in Properties.Settings.Default.Properties)\n{\n Console.WriteLine(_currentProperty.Name + "," + _currentProperty.DefaultValue.ToString());\n}\nRun Code Online (Sandbox Code Playgroud)\n\n上面的循环显示了属性的原始值(旧的默认值是AAA)。
我已检查该user.config文件并确保它正在显示NewValue。
我假设必须有某种方法使用我不知道的属性或方法来引用当前值(也许我应该迭代另一个集合?)。
\n\n问题是,如何在foreach上面的循环中显示这个新值?