[英]Custom sort of a SortedSet in VB.Net
I have a sortedSet with following data: 我有一个带有以下数据的sortedSet:
aga12
aga44
dp1
dp11
reg13
reg45
sat5
sat6
I would like this list to be sorted aphabetically but I want the dp values to be on top so like this: 我希望此列表按字母顺序排序,但我希望dp值位于最前面,如下所示:
dp1
dp11
aga12
aga44
reg13
reg45
...
Anyone know how I can custom sort this SortedSet. 任何人都知道如何自定义对SortedSet排序。 I am using VB.NET
我正在使用VB.NET
thanks 谢谢
You could sort using a custom compare class 您可以使用自定义比较类进行排序
Dim myList As New List(Of String)
....
myList.Sort(New DpCompare)
And 和
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.