排序字典按值与LINQ在vb.net [英] Sorting a dictionary by value with linq in vb.net
问题描述
我想要一本字典按值与LINQ排序,但我想不出如何ToDictionary()方法的工作原理。
I'm trying to sort a dictionary by value with LINQ but I can't figure how the ToDictionary() method works.
所有的例子我能看到的是用C#。
All the examples I can find are in c#.
这是我的code
Dim f As Dictionary(Of String, String) = (From value In projectDescriptions.Values
Order By value Ascending
Select value).ToDictionary(???)
更新
最后,我才意识到这是愚蠢的。对不起
Finally, I just realized that was stupid. Sorry
我做了一个列表(keyValuePair的(字符串,字符串))
I did a list (of keyValuePair(of string,string))
和整理我的名单,我
mylist.OrderBy(Function(x) x.Value).ToList()
希望这将帮助别人
hope it will help someone
推荐答案
你说你没发现这样的一个例子,但检查的 MSDN此处。类似下面应该工作在VB。
You said you didn't find an example of this, but check MSDN here. Something like the following should work in VB.
'not sure what the key is, but use whichever property you'd like
Dim f As Dictionary(Of String, String) =
(From value In projectDescriptions.Values
Order By value Ascending
Select value).ToDictionary(Function(p) p.Key)
但是,如果你在字典中存储的排序枚举再次,它成为未分类,这是在一般的字典或地图的一个属性,是precisely为什么词典是如此之快和流行。如果你需要它有序,也许你想使用 SortedDictionary
呢?
But if you store a sorted enumerator in a dictionary again, it becomes unsorted, that's a property of a dictionary or map in general and is precisely why dictionaries are so fast and popular. If you need it sorted, perhaps you want to use SortedDictionary
instead?
这篇关于排序字典按值与LINQ在vb.net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!