【发布时间】:2014-09-23 11:50:55
【问题描述】:
我有一个 Winforms/C# 应用程序,我正在从 xml 配置文件迁移到应用程序设置。我想知道是否可以动态访问应用程序设置(Properties.Settings.Default)。
我的应用程序有 4 种可能的配置以及相关设置,我在逻辑上命名为 name1、name2、name3、name4、server1、server2 等。 而不是为它们分配一个像
这样的值Properties.Settings.Default.name1 = textbox.txt;
我想就它们所属的配置做这样的事情:
class ApplicationSettings
{
int no;
ApplicationSettings(int no)
{
this.no = no;
}
private void save()
{
Properties.Settings.Default.Properties["name"+no] = "value";
}
}
该技术似乎仅适用于 SettingsProperties,如 here 所示。你知道有没有办法做到这一点?
【问题讨论】:
-
Properties.Settings.Default["name"+no.ToString()] = "value" ??
-
好吧,很明显,我没有发现它会起作用! ://