【发布时间】:2014-09-19 18:08:43
【问题描述】:
我有一个:
var selectedDates = new Dictionary<string, string>();
selectedDates.Add("2014-06-21", DateTime.Now.ToLongDateString());
selectedDates.Add("2014-07-21", DateTime.Now.AddDays(5).ToLongDateString());
selectedDates.Add("2014-08-21", DateTime.Now.AddDays(9).ToLongDateString());
selectedDates.Add("2014-09-21", DateTime.Now.AddDays(14).ToLongDateString());
如何在不知道密钥的情况下循环遍历项目?
例如我想获取 item[0]
的值
如果我这样做:
var item = selectedDates[0].value; // I get an error
【问题讨论】:
-
你希望第一个项目是什么?
-
那为什么要使用字典呢?数组或列表不能完成这项工作吗?
-
如果您不知道如何遍历字典,或者您在不知道键值的情况下引用字典中的特定条目时遇到问题,能否解释一下?
标签: c# idictionary