这是我的App.Config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="lang" value="English"/>
</appSettings>
</configuration>
Run Code Online (Sandbox Code Playgroud)
使用此代码,我进行了更改
lang = "Russian";
private void Main_FormClosing(object sender, FormClosingEventArgs e)
{
System.Configuration.ConfigurationManager.AppSettings.Set("lang", lang);
}
Run Code Online (Sandbox Code Playgroud)
但它没有改变.我做错了什么?
我正在使用.NET 4.0,我想使用该app.config文件来存储相同的参数设置.我做了以下事情.我使用Settings项目属性中的选项卡来创建我的参数.
这样就可以app.config像这样在文件中添加信息:
<MyApp.Properties.Settings>
<setting name="param1" serializeAs="String">
<value>True</value>
</setting>
<MyApp.Properties.Settings>
Run Code Online (Sandbox Code Playgroud)
在我的视图模型中(在我的代码中),我可以通过这种方式访问信息:
bool myBool = MyApp.Properties.Default.param1;
Run Code Online (Sandbox Code Playgroud)
当我尝试更改配置文件中的值时,我尝试这样做:
Properties.Settings.Default.param1 = false;
Run Code Online (Sandbox Code Playgroud)
但这会导致错误,即param1只读.
那么如何从我的代码更新我的配置文件?