十分简单

Linux_9 2008-06-04 02:32:21


'[code=VB]

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
[/code]
...全文
82 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
Linux_9 2008-06-04
  • 打赏
  • 举报
回复

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
Linux_9 2008-06-04
  • 打赏
  • 举报
回复
[code=vb.net]
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
[/code]
ericzhangbo1982111 2008-06-04
  • 打赏
  • 举报
回复
Public Class ProductInfo
Implements IComparable'这里这句话是做什么用的 实现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'还有这里,能否解释哈哈实现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
Linux_9 2008-06-04
  • 打赏
  • 举报
回复

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

16,554

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧