Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net 通过引用将参数传递到公共共享方法中的问题_Vb.net_List_Visual Studio 2005 - Fatal编程技术网

Vb.net 通过引用将参数传递到公共共享方法中的问题

Vb.net 通过引用将参数传递到公共共享方法中的问题,vb.net,list,visual-studio-2005,Vb.net,List,Visual Studio 2005,我有一个AddlInfo列表,其中AddlInfo是一个对象 我试图通过引用将addlInfoList传递到另一个类的函数中: 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 AddlI

我有一个AddlInfo列表,其中AddlInfo是一个对象

我试图通过引用将addlInfoList传递到另一个类的函数中:

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
如果我没有将引用传递到另一个类中,则此操作有效,但当我尝试这样做时,会出现以下错误:

重载解析失败,因为无法使用以下参数调用可访问的“Sort”:

我可以将这些方法放回调用类,但我希望能够从应用程序中的不同类调用这些方法

我还可以在方法中实例化一个新列表,但为什么呢?看起来很傻

有办法吗?(或者我需要进一步解释吗?)


提前谢谢

尝试将比较函数放入实现IComparer的类中。

Matthew:感谢您的响应。我试过了你的建议,但我想我已经做得太过分了你能告诉我你的建议能达到什么效果吗?我想我的问题是不合适的,所以我接受你的答案,然后继续。John,你想做什么?创建一个新类并让它实现IComparer。然后IDE将为您创建比较函数,您需要做的就是将代码放入比较中。然后,创建该类的实例,并将其传递到AddInfo对象的Sort方法中。查看此URL了解更多信息:请特别注意示例中使用的CMySort类。
'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.