相关疑难解决方法(0)

从字典中获取第一个元素

我有以下声明:

Dictionary<string, Dictionary<string, string>> like = new Dictionary<string, Dictionary<string, string>>();
Run Code Online (Sandbox Code Playgroud)

我需要获取第一个元素,但不知道键或值.最好的方法是什么?

.net c# asp.net .net-3.5

44
推荐指数
4
解决办法
13万
查看次数

字典的枚举器<TKey,TValue>是否按照添加的顺序返回键值对?

我知道字典不是有序集合,不应该依赖于字典中插入和检索的顺序.

但是,这是我注意到的:

  • 为Dictionary添加了20个键值对
  • 通过做foreach(KeyValuePair ...)检索它们

检索顺序与添加顺序相同.测试了大约16个键值对.

这是设计的吗?

.net c# collections

17
推荐指数
2
解决办法
4009
查看次数

c#Dictionary <string,string>如何在不知道密钥的情况下循环遍历项目

我有一个:

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)

c# idictionary

7
推荐指数
2
解决办法
4312
查看次数

字典中的第一项

我有一个按降序排序的字典.每个字符串(键)是一个术语,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)

c# c#-4.0

0
推荐指数
1
解决办法
4331
查看次数

标签 统计

c# ×4

.net ×2

.net-3.5 ×1

asp.net ×1

c#-4.0 ×1

collections ×1

idictionary ×1