【发布时间】:2011-05-12 03:15:34
【问题描述】:
这是我正在使用的代码:
private void SaveConfiguration()
{
if (txtUsername.Text != "" && txtPassword.Text != "")
{
ConfigurationManager.AppSettings["Username"] = txtUsername.Text;
ConfigurationManager.AppSettings["Password"] = txtPassword.Text;
MessageBox.Show("Su configuracion guardo exitosamente.", "Exito!");
this.Close();
}
else
{
MessageBox.Show("Por favor lleno los campos.", "Error.");
}
}
现在,设置已保留,但当我关闭应用程序并按 F5 再次运行它时,值将恢复为在 app.config 文件中键入的值。有什么建议吗?
【问题讨论】:
-
您可能应该考虑使用 string.IsNullOrEmpty(...) 而不是与 "" 进行比较 :)
标签: c# app-config