【发布时间】:2012-05-30 16:37:57
【问题描述】:
我有一个List(of String())。我编写了一个自定义比较器 (implements IComparer(of string)) 来进行字母数字排序。
有没有办法使用给定的索引对列表进行排序,以确定String() 中的哪个位置进行排序?换句话说,一次我可能会按Index = 0 排序,另一次可能会按Index = 3 排序。列表中所有String() 的长度相同。
作为参考,这个问题类似于 Sort List<String[]>,除了我使用的是 VB.net 并且这个问题是硬连线到 Index=0。
从 OP 的 cmets 编辑:
我从简单的非自定义比较器开始,但出现错误:表达式不产生值。不知道我做错了什么。 这是代码:
Public Shared Function SortListOfStringArray(ByVal ListOfStringArray As List(Of String()), ByVal SortByIndex As Integer) As List(Of String())
Return ListOfStringArray.Sort(Function(x, y) x(SortByIndex).CompareTo(y(SortByIndex)))
End Function
【问题讨论】: