简体   繁体   中英

Iterating properties in Properties.Settings.Default

I've got a Visual Studio project that contains a few StringCollections under app settings. I want to iterate over these properties/settings at runtime but can't find a way to do so. I've tried this:

foreach (SettingsProperty prop in Properties.Settings.Default.Properties)
   string className = (prop.DefaultValue as StringCollection)[1];

But prop.DefaultValue is not a StringCollection and returns null. I realize I can use Properties.Settings.Default["SettingName"] but that requires me to know the setting name beforehand. There has to be a way to iterate through the application setting names and read their associated StringCollection values, but how? I can't find an example after hours of searching.

How about using

if(Properties.Settings.Default[prop.Name] is StringCollection sc){
    ...
}

in your loop?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM