我有一个对象列表,用于存储我所做的提要搜索的搜索结果。在添加到列表时,我给对象一个结果相关性的分数,以便我可以将这些结果推到顶部。
我的对象实现了IComparable
接口并具有 compareto 函数并且所有编译都正确但是当我对列表进行排序时(list.sort())这似乎对结果没有任何影响(得分较高的项目不在顶部底端)
谁能告诉我我做错了什么?
Public Class SearchFeedItem
Implements IComparable
Private _score As Integer = 0
Public Property Score() As Integer
Get
Return _score
End Get
Set(ByVal value As Integer)
_score = value
End Set
End Property
Public Function CompareTo(ByVal obj As Object) As Integer Implements System.IComparable.CompareTo
Dim OtherItem As SearchFeedItem = CType(obj, SearchFeedItem)
If Me.Score < OtherItem.Score Then
Return 1
End If
If Me.Score > OtherItem.Score Then
Return -1
Else
Return 0
End If
End Function
End Class