string[] Accounts = ConfigurationManager.AppSettings.AllKeys
.Where(key => key.StartsWith("Account"))
.Select(key => ConfigurationManager.AppSettings[key])
.ToArray();
在这里,我得到了所有的 AppSettings
以 Account
开头的但目前它们只返回对象的值。
有什么方法可以转 string[] Accounts
进入List<Tuple<String, String>> Accounts
所以就像List<Tuple<key, value>> Accounts
最佳答案
当然 - 您需要做的就是更改 Select
以返回所需的元组,并调用 ToList
代替 ToArray
:
List<Tuple<String,String>> Accounts = ConfigurationManager.AppSettings.AllKeys
.Where(key => key.StartsWith("Account"))
.Select(key => Tuple.Create(key, ConfigurationManager.AppSettings[key]))
.ToList();
关于c# - 获取 ConfigurationManager.AppSettings 键名和值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49348195/