簡體   English   中英

在 Properties.Settings.Default 中迭代屬性

[英]Iterating properties in Properties.Settings.Default

我有一個 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){
    ...
}

在你的循環中?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM