我在项目中使用它来保存 app.config 中的字符串连接:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="ContaTroco.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
</sectionGroup>
</configSections>
<userSettings>
<ContaTroco.Properties.Settings>
<setting name="servidor" serializeAs="String">
<value />
</setting>
<setting name="banco" serializeAs="String">
<value />
</setting>
<setting name="usuario" serializeAs="String">
<value />
</setting>
<setting name="senha" serializeAs="String">
<value />
</setting>
</ContaTroco.Properties.Settings>
</userSettings>
在 C# 的代码中我使用这个
servidor = comboBox1.SelectedValue.ToString();
usuario = txtUsuario.Text;
password = txtPassword.Text;
catalog = cmbBancos.Text;
Properties.Settings.Default.servidor = servidor;
Properties.Settings.Default.banco = catalog;
Properties.Settings.Default.usuario = usuario;
Properties.Settings.Default.senha = password;
Properties.Settings.Default.Save();
这些代码在一个项目中完美运行,但是当我将表单导入其他项目时(添加现有项目并重命名命名空间)我在这部分出现错误“当前上下文中不存在名称'属性'”,我有将 system.configuration 引用添加到项目中,但错误仍在继续。感谢任何帮助。