【发布时间】:2013-01-16 09:07:45
【问题描述】:
如何在Dictionary中存储多个不同的值?
我这里有一个代码:
Dictionary<string, DateTime> SearchDate = new Dictionary<string, DateTime>();
SearchDate.Add("RestDate", Convert.ToDateTime("02/01/2013"));
SearchDate.Add("RestDate", Convert.ToDateTime("02/28/2013"));
但在字典中我了解到只允许使用一个唯一键,所以我的代码产生了错误。
【问题讨论】:
-
你需要一个
Dictionary<string, List<DateTime>> -
这称为"Multimap",不能由 IDictionary 合约实现(尽管您可以手动执行
Dictionary<string,IList<DateTime>>或类似操作)。如果使用 LINQ,请考虑使用 Lookup,尽管它有其他含义。 -
stackoverflow.com/questions/569903/multi-value-dictionary , stackoverflow.com/questions/3639972/… , stackoverflow.com/questions/10089850/… , stackoverflow.com/questions/2101069/… 等(-1 因为我用
[c#] dictionary multiple和[c#] dictionary many找到了这些 - 你也可以拥有!)跨度>
标签: c# dictionary