我有一个清单(Of AddlInfo),而AddlInfo是一个物体。
页: 1 参考另一个类别的功能:
Public Shared Sub SortAddlInfo(ByRef addlInfoList As List(Of AddlInfo))
addlInfoList.Sort(AddressOf Comparer)
End Sub
Private Function Comparer(ByVal x As AddlInfo, ByVal y As AddlInfo) As Integer
Dim result As Integer = x.AddlInfoType.CompareTo(y.AddlInfoType)
Return result
End Function
如果我不把提及内容提上另一类,但当我试图这样做时,我有以下错误:
过重的解决失败是因为不能用这些论点来找准人:
Public Sub Sort(comparison As System.Comparison(Of AddlInfo)) : Cannot refer to an instance member of a class from within a shared method or shared member initializer without an explicit instance of the class.
Public Sub Sort(comparer As System.Collections.Generic.IComparer(Of AddlInfo)) : AddressOf expression cannot be converted to System.Collections.Generic.IComparer(Of MyProject.AddlInfo) because System.Collections.Generic.IComparer(Of MyProject.AddlInfo) is not a delegate type.
我可以把这些方法重新归入打电话的类别,但我想能够在我的申请范围内从不同类别中讲这些方法。
我也可以在方法上提出新的清单,但为什么? Seems silly。
如何解决这一问题? (我是否需要作更多的解释?)
提前感谢!