我有一个带有以下数据的sortedSet:
aga12
aga44
dp1
dp11
reg13
reg45
sat5
sat6
我希望此列表按字母顺序排序,但我希望dp值位于顶部,如下所示:
dp1
dp11
aga12
aga44
reg13
reg45
...
任何人都知道我如何自定义排序这个SortedSet。我正在使用VB.NET
谢谢
答案 0 :(得分:1)
您可以使用自定义比较类进行排序
Dim myList As New List(Of String)
....
myList.Sort(New DpCompare)
和
Private Class DpCompare
Implements IComparer(Of String)
Public Function Compare(ByVal x As String, ByVal y As String) As Integer Implements System.Collections.Generic.IComparer(Of String).Compare
Dim isDPx As Boolean = x.StartsWith("dp")
Dim isDPy As Boolean = y.StartsWith("dp")
If isDPx AndAlso isDPy = False Then
Return -1
End If
If isDPy AndAlso isDPx = False Then
Return 1
End If
Return String.Compare(x, y)
End Function
End Class