16,554
社区成员
发帖
与我相关
我的任务
分享
'[code=VB]
Public Function CompareTo(ByVal obj As Object) As Integer _
Implements IComparable.CompareTo
'还有这里,能否解释哈哈实现IComparable
'这个接口里面的CompareTo'方法
'我没有明白放在这里为什么,没有找到用处···
Dim p As ProductInfo = CType(obj, ProductInfo)
'产品价格的比较
If (p._productPrice > _productPrice) Then Return -1
If (p._productPrice < _productPrice) Then Return 1
Return 0
End Function
Public Class ProductInfo
Implements IComparable'这里这句话是做什么用的
Public _productName As String
Public _productPrice As Decimal
Public Sub New(ByVal name As String, ByVal price As Decimal)
_productName = name
_productPrice = price
End Sub
Public Function CompareTo(ByVal obj As Object) As Integer _
Implements IComparable.CompareTo'还有这里,能否解释哈哈
Dim p As ProductInfo = CType(obj, ProductInfo)
'产品价格的比较
If (p._productPrice > _productPrice) Then Return -1
If (p._productPrice < _productPrice) Then Return 1
Return 0
End Function
End Class