我目前在下面使用这个方法,它工作得很好,我只想知道你是如何将元组上的CompareTo链起来进行Item2第一次排序,然后在Item2排序完成后进行Item1第二次排序的,就像GroupBy/then一样。你是如何把它们链在一起的?
Dim newListOfValues As List(Of KeyValuePair(Of Tuple(Of Integer, Integer), Byte)) = ListOfValues.ToList()
newListOfValues.Sort(
Function(pair1 As KeyValuePair(Of Tuple(Of Integer, Integer), Byte), pair2 As KeyValuePair(Of Tuple(Of Integer, Integer), Byte))
Return pair1.Key.Item2.CompareTo(pair2.Key.Item2) AndAlso pair1.Key.Item1.CompareTo(pair2.Key.Item1)
End Function)
现在这个代码也没什么不同
newListOfValues.Sort(
Function(pair1 As KeyValuePair(Of Tuple(Of Integer, Integer), Byte), pair2 As KeyValuePair(Of Tuple(Of Integer, Integer), Byte))
Return pair1.Key.Item2.CompareTo(pair2.Key.Item2)
End Function)
问题是它无论如何都很完美,所以我想不需要额外的比较