标题:帮帮忙,谢谢
只看楼主
wangfuli
Rank: 4
等 级:贵宾
威 望:12
帖 子:206
专家分:10
注 册:2005-11-11
 问题点数:0 回复次数:0 
帮帮忙,谢谢

小弟是个新手,刚学vb.net很短时间了,模块和类把我搞的很是头疼,下面是我刚学的一个例子,运行时老是提示:指定的 IComparer 引发异常。我很是迷茫,请问哪错了,为什么了?小弟先谢了!

Module Module1
Structure money
Implements IComparable
Private centsamount As Int16
Private Const currencysymbol As String = "$"
Public Sub New(ByVal dollars As Int16, ByVal cents As Int16)
Me.centsamount = (dollars * 100) + cents
End Sub
Public Sub New(ByVal amount As Int16)
Me.centsamount = CInt(amount * 100)
End Sub
Public Function compareto(ByVal other As Object) As Int16 Implements IComparable.CompareTo
Dim m2 As money = CType(other, money)
If Me.centsamount < m2.centsamount Then
Return -1
ElseIf Me.centsamount = m2.centsamount Then
Return 0
Else
Return 1
End If
End Function
Public Overrides Function tostring() As String
Return currencysymbol & CStr(Me.centsamount / 100)
End Function
End Structure
Sub main()
Dim salaries(4) As money
salaries(0) = New money(9)
salaries(1) = New money(4)
salaries(2) = New money(8)
salaries(3) = New money(6)
Console.WriteLine("unsorted array")
Dim salary As money
For Each salary In salaries
Console.WriteLine("{0}", salary)
Next
Array.Sort(salaries)
Console.WriteLine(vbCrLf & "sorted array")
For Each salary In salaries
Console.WriteLine("{0}", salary)
Next
End Sub
End Module

搜索更多相关主题的帖子: dollars money 
2005-12-08 20:55



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-37367-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.135817 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved