I have a List (Of AddlInfo) with an AddlInfo object being an object.
I am trying to pass addlInfoList by reference to a function of another class:
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
This works if I do not pass the link to another class, but when I try to do this, I get the following error:
An overload error is not possible because access to Sort cannot be called with these arguments:
'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.
I could return the methods back to the calling class, but I would like to be able to call these methods from different classes in my application.
I could also create a new list in the methods, but why? Seems stupid.
How to get around this? (Or do I need to explain more?)
Thanks in advance!
John
source share