如何实现VB.NET中字典键的反向顺序排序?
- 内容介绍
- 文章标签
- 相关推荐
本文共计187个文字,预计阅读时间需要1分钟。
我有这样一个字典:`Dim dicItems As Dictionary(Of Integer, String)` 字典中的项目是:`1,cat2,dog3,bird` 我希望订单是:`3,bird2,dog1,cat` 您可以使用LINQ轻松解决这个问题:`Dim dicItems As New Dictionary(Of Integer, String)`
我有一本字典: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)
本文共计187个文字,预计阅读时间需要1分钟。
我有这样一个字典:`Dim dicItems As Dictionary(Of Integer, String)` 字典中的项目是:`1,cat2,dog3,bird` 我希望订单是:`3,bird2,dog1,cat` 您可以使用LINQ轻松解决这个问题:`Dim dicItems As New Dictionary(Of Integer, String)`
我有一本字典: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)

