我有以下声明:
Dictionary<string, Dictionary<string, string>> like = new Dictionary<string, Dictionary<string, string>>();
Run Code Online (Sandbox Code Playgroud)
我需要获取第一个元素,但不知道键或值.最好的方法是什么?
我知道字典不是有序集合,不应该依赖于字典中插入和检索的顺序.
但是,这是我注意到的:
检索顺序与添加顺序相同.测试了大约16个键值对.
这是设计的吗?
我有一个:
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());
Run Code Online (Sandbox Code Playgroud)
如何在不知道密钥的情况下循环项目?
例如,我想得到项[0]的值
如果我做:
var item = selectedDates[0].value; // I get an error
Run Code Online (Sandbox Code Playgroud) 我有一个按降序排序的字典.每个字符串(键)是一个术语,int(值)是它的计数.我如何得到第一个计数?因为它指的是最大数量(频率).......提前感谢.
Just to inform some of whom commented that the dictionary<string,int> will change its
rank. Be sure, if you are grouping the dictionary by its count, there is no problem
with the order . Always the dictionary will come with highest count at first.
Run Code Online (Sandbox Code Playgroud)