Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net dotnet:有没有办法直接在字典中获取值集合的引用?_.net_Sorting_Collections_Dictionary - Fatal编程技术网

.net dotnet:有没有办法直接在字典中获取值集合的引用?

.net dotnet:有没有办法直接在字典中获取值集合的引用?,.net,sorting,collections,dictionary,.net,Sorting,Collections,Dictionary,我想根据每个dictionary条目的值对dictionary进行排序。但如果使用排序后的dictionary搜索,时间复杂度将从常量增加到log2(n)。所以我想直接将字典中的值列表的引用分配给一个列表。然后我可以对这个列表进行排序并得到结果。我不想迭代字典中的每个元素以在列表中添加它的值,这会增加复杂性吗 您可以通过字典.values属性获取值集合。在下面的示例中,您不会循环遍历值,但框架会为您执行 Dictionary<int, Item> items = new Dictio

我想根据每个dictionary条目的值对dictionary进行排序。但如果使用排序后的dictionary搜索,时间复杂度将从常量增加到log2(n)。所以我想直接将字典中的值列表的引用分配给一个列表。然后我可以对这个列表进行排序并得到结果。我不想迭代字典中的每个元素以在列表中添加它的值,这会增加复杂性吗

您可以通过
字典.values
属性获取值集合。在下面的示例中,您不会循环遍历值,但框架会为您执行

Dictionary<int, Item> items = new Dictionary<int, Item>();
List<Item> values = new List<Item>(items.Values);
values.Sort();
Dictionary items=newdictionary();
列表值=新列表(items.values);
value.Sort();
您还可以为值保留另一个列表,并且可以将项目添加到字典和列表中