[英]Is there a way to sort keys in dictionary in vb.net
http://msdn.microsoft.com/en-us/library/xfhwa508%28v=vs.110%29.aspx
說我想為每個鍵上的每個鍵做一個操作,並且我希望像字母“ BR”這樣按字母順序排列的較小鍵首先出現。
有辦法嗎?
還是字典嚴格是關鍵對象對?
我找到此鏈接作為解決方案
http://www.dotnetperls.com/sort-dictionary-vbnet
基本上將鍵插入列表,然后對該列表進行排序,然后根據該列表進行枚舉。
我復制粘貼示例代碼
Sub Main()
' Create Dictionary with string keys.
Dim dict As New Dictionary(Of String, Integer)
dict.Add("dog", 0)
dict.Add("cat", 1)
dict.Add("mouse", 5)
dict.Add("eel", 3)
dict.Add("programmer", 2)
' Get list of keys.
Dim keys As List(Of String) = dict.Keys.ToList
' Sort the keys.
keys.Sort()
' Loop over the sorted keys.
Dim str As String
For Each str In keys
Console.WriteLine("{0} -> {1}", str, dict.Item(str))
Next
End Sub
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.