按键对字典(列表(整数),列表(整数))进行排序

时间:2019-06-02 18:00:24

标签: vb.net

如何通过键对字典(列表(整数),列表(整数))进行排序

Dim sortedL As List(Of KeyValuePair(Of List(Of Integer), List(Of Integer))) = dict2UzOsnova.ToList
sortedL.Sort(Function(firstPair As KeyValuePair(Of List(Of Integer), List(Of Integer)), nextPair As KeyValuePair(Of List(Of Integer), List(Of Integer))) _
    CInt(firstPair.Key.ElementAt(0).CompareTo(CInt(nextPair.Key.ElementAt(0)))))

此键仅按键中的第一个数字排序(图像不是来自sortedL,这是指我的字典名称dict2UzOsnova,以便随后进行排序 enter image description here

1 个答案:

答案 0 :(得分:0)

将dict2UzOsnova用作新字典(列表(整数),列表(整数))         将listKey1变暗为新List(Integer)(New Integer(){2,8,12,13})         Dim listValue1 As New List(Of Integer)(New Integer(){43,51,57,59,71,200,207,211,238})         dict2UzOsnova.Add(listKey1,listValue1)

    Dim listKey2 As New List(Of Integer)(New Integer() {2, 5, 12, 13})
    Dim listValue2 As New List(Of Integer)(New Integer() {37, 76, 77, 86, 89, 104, 116, 190, 230})
    dict2UzOsnova.Add(listKey2, listValue2)

    Dim listKey3 As New List(Of Integer)(New Integer() {2, 5, 10, 12})
    Dim listValue3 As New List(Of Integer)(New Integer() {37, 56, 57, 66, 79, 100, 123, 178, 230})
    dict2UzOsnova.Add(listKey3, listValue3)

    Dim listKey4 As New List(Of Integer)(New Integer() {1, 2, 12, 13})
    Dim listValue4 As New List(Of Integer)(New Integer() {43, 50, 55, 61, 88, 105, 112, 178, 309})
    dict2UzOsnova.Add(listKey4, listValue4)
    ''etc... Now should be sorted by key(maybe over IComparer).
    ''After Sort my dictionary dict2UzOsnova  I need to get as pictured above right AFTER SORTED or under:
    '                    >key (0) (1) (2) (3)  >Value (0) (1)  (2) (3) (4) (5)  (6)  (7)  (8) 
    ' dict2UzOsnova (0)        1   2  12  13          43  50   55  61  88  105  112  178  309
    ' dict2UzOsnova (1)        2   5  10  12          37  56   57  66  79  100  123  178  230
    ' dict2UzOsnova (2)        2   5  12  13          37  76   77  86  89  104  116  190  230
    ' dict2UzOsnova (3)        2   8  12  13          43  51   57  59  71  200  207  211  238