我有一个Visual Studio项目,在应用程序设置下包含一些StringCollections。我想在运行时迭代这些适当的设置,但找不到方法。我试过这个方法。
foreach (SettingsProperty prop in Properties.Settings.Default.Properties)
string className = (prop.DefaultValue as StringCollection)[1];
但是... prop.DefaultValue
不是 StringCollection
并返回null。我知道我可以使用 Properties.Settings.Default["SettingName"]
但这需要我事先知道设置名称。必须有一种方法来迭代应用程序的设置名称,并读取它们相关的 StringCollection
值,但是怎么做呢?我找了几个小时也没找到一个例子。
如何使用
if(Properties.Settings.Default[prop.Name] is StringCollection sc){
...
}
在你的圈子里?