使用数组 (VB.NET) 的值进行排序



输入:

i = 768
arrayInt(i) = 258
arrayIntCombine(i) = 256
arrayByte(i) = 32
i = 1632
arrayInt(i) = 256
arrayIntCombine(i) = 112
arrayByte(i) = 97
i = 1824
arrayInt(i) = 259
arrayIntCombine(i) = 32
arrayByte(i) = 112
i = 1889
arrayInt(i) = 257
arrayIntCombine(i) = 97
arrayByte(i) = 112
i = 2016
arrayInt(i) = 260
arrayIntCombine(i) = 256
arrayByte(i) = 110
..... (more input)

我想要这样的输出(文本或消息框(:

No. 256 : 112 and 97
No. 257 : 97 and 112
No. 258 : 256 and 32
No. 259 : 32 and 112
No. 260 : 256 and 110
...... (more output)

我已经尝试过从按数字对数组进行排序 (VB.NET( 中 array.sort 但它不起作用

你可以使用元组:

    Dim DictionaryOfTuples As New Dictionary(Of Integer, Tuple(Of Integer, Integer, Integer))
    DictionaryOfTuples(768) =
        New Tuple(Of Integer, Integer, Integer)(258, 256, 32)
    DictionaryOfTuples(1632) =
        New Tuple(Of Integer, Integer, Integer)(256, 112, 97)
    DictionaryOfTuples(1824) =
        New Tuple(Of Integer, Integer, Integer)(259, 32, 112)
    DictionaryOfTuples(1889) =
        New Tuple(Of Integer, Integer, Integer)(257, 97, 112)
    DictionaryOfTuples(2016) =
        New Tuple(Of Integer, Integer, Integer)(260, 256, 110)
    Dim output As New System.Text.StringBuilder
    For Each sortedTuple In DictionaryOfTuples.Values.OrderBy(Function(t) t.Item1)
        output.AppendLine(
            String.Format(
                "No. {0} : {1} and {2}",
                sortedTuple.Item1,
                sortedTuple.Item2,
                sortedTuple.Item3))
    Next
    MsgBox(output.ToString)

最新更新