我有一本字典: Dim dicItems As Dictionary(of Integer, String) 字典中的项目是: 1,cat2,dog3,bird 我希望订单是: 3,bird2,dog1,cat 您可以使用LINQ轻松解决此问题: Dim dicItems As New Dictionary(Of Integer, Str
Dim dicItems As Dictionary(of Integer, String)
字典中的项目是:
1,cat 2,dog 3,bird
我希望订单是:
3,bird 2,dog 1,cat您可以使用LINQ轻松解决此问题:
Dim dicItems As New Dictionary(Of Integer, String) With dicItems .Add(1, "cat") .Add(2, "dog") .Add(3, "bird") End With dim query = from item in dicItems order by item.Key descending select item
如果需要,还可以使用Lambda语法:
Dim query = dicItems.OrderByDescending(Function(item) item.Key)