【发布时间】:2014-12-02 05:41:12
【问题描述】:
public static IEnumerable<KeyValuePair<string, string>> GetGroupKeyValuePairs(string category)
{
var list = new List<KeyValuePair<string, string>>();
using (DataConnection connection = new DataConnection())
{
List<KeyValuePair<string,string>> settings = connection.Get<Settings>()
.Where(a => a.Category == category )
.Select(pair => new KeyValuePair<string,string>(pair.TheName, pair.TheValue))
.ToList();
list = settings;
}
return list;
}
例外是:
无效操作异常: 键“Garanti.Oda”出现不止一次
如何收集重复的密钥?
【问题讨论】:
-
@mybirthname:OP 应该能够使用相同的密钥创建尽可能多的
KeyValuePair实例,并且他们应该能够将尽可能多的实例添加到简单的List中他们喜欢。该结构本身没有任何东西可以阻止同一密钥同时存在于多个KeyValuePair结构中。 -
@O.R.Mapper 我将阅读有关键值对的信息以检查您写的内容,我使用它们 2-3 次可能是我的错误。谢谢!
-
@mybirthname: dotnetfiddle.net/SElgkq
-
@OrelEraki:你是怎么知道他们“不能”的?另外,您指的是什么
NameValuePair类型?来自Microsoft.Build.Framework.XamlTypes的那个?还是来自Microsoft.Rtc.Signaling的那个?这些听起来都不应该或不能从 3rd 方通用代码中使用。 -
@O.R.Mapper 绝对正确..
标签: c#