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
答案 0 :(得分:1)
绝对 - 您需要做的就是更改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();