VB.NET:按字母顺序排列词典

VB.NET:按字母顺序排列词典,vb.net,linq,sorting,dictionary,Vb.net,Linq,Sorting,Dictionary,我有一个字符串,Item的字典,我试着按照Item名称的字母顺序对它进行排序。我不想使用分类的词汇,没有它,我就没有运气了。林克不是我的强项 Public Class Item Public Property name As String Public Property size As String Public Property price As Decimal Public Property timeMachine As Boolean End Class

我有一个字符串,Item的字典,我试着按照Item名称的字母顺序对它进行排序。我不想使用分类的词汇,没有它,我就没有运气了。林克不是我的强项

Public Class Item
    Public Property name As String
    Public Property size As String
    Public Property price As Decimal
    Public Property timeMachine As Boolean
End Class
作为TKey的字典,TValue本质上是一种无序类型。没有办法对一个进行分类。尝试使用TKey的SortedDictionary,而不是TValue

Dim map = new SortedDictionary(Of String, Item)()
作为TKey的字典,TValue本质上是一种无序类型。没有办法对一个进行分类。尝试使用TKey的SortedDictionary,而不是TValue

Dim map = new SortedDictionary(Of String, Item)()

1获取键列表,2对键进行排序,3根据排序后的键获取字典值

Dim keys As List(Of String) = dictionary.Keys.ToList
keys.Sort()

For Each str As String In Keys
  Console.WriteLine("{0} -> {1}", str, dictionary.Item(str))
Next

1获取键列表,2对键进行排序,3根据排序后的键获取字典值

Dim keys As List(Of String) = dictionary.Keys.ToList
keys.Sort()

For Each str As String In Keys
  Console.WriteLine("{0} -> {1}", str, dictionary.Item(str))
Next

您应该实现Isortable和其他一些接口,或者使用SortedDictionary或其他实现这些接口的列表类。为什么不使用SortedDictionary?您应该实现Isortable和其他一些接口,或者使用SortedDictionary或其他实现这些接口的列表类。为什么不使用SortedDictionary分类词典?