首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > VB Dotnet >

十分简单解决方案

2012-02-12 
十分简单VB code[codeVB]Public Class ProductInfoImplements IComparable这里这句话是做什么用的Publi

十分简单

VB code
'[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]

[解决办法]
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 

热点排行