views:

132

answers:

2

I cannot figure out how to convert this code from C# to VB.net. It says - Argument not specified for parameter ‘y’ in the calling code below.

Any suggestions?

Thanks


Calling CODE:

list.Sort(Utility.CompareContactListsBySortOrder) - error here in VB

CODE:

    /// <summary>
    /// Defines the compare criteria for two Contact List instances
    /// </summary>
    /// <param name="x">Contact List to be compared</param>
    /// <param name="y">Contact List to be compared</param>
    /// <returns></returns>
    public static int CompareContactListsBySortOrder(ContactList x, ContactList y)
    {
        if (x.SortOrder.HasValue && y.SortOrder.HasValue)
        {
            return x.SortOrder.Value.CompareTo(y.SortOrder.Value);
        }

        return 0;
    }


''' <summary>
''' Defines the compare criteria for two Contact List instances
''' </summary>
''' <param name="x">Contact List to be compared</param>
''' <param name="y">Contact List to be compared</param>
''' <returns></returns>
Public Shared Function CompareContactListsBySortOrder(ByVal x As ContactList, ByVal y As ContactList) As Integer
    If x.SortOrder.HasValue AndAlso y.SortOrder.HasValue Then
        Return x.SortOrder.Value.CompareTo(y.SortOrder.Value)
    End If

    Return 0
End Function

Private Shared Function InlineAssignHelper(Of T)(ByRef target As T, ByVal value As T) As T
    target = value
    Return value
End Function
+2  A: 
list.Sort(AddressOf Utility.CompareContactListsBySortOrder)

In VB, you use the AddressOf operator to take the address of method to create a delegate. In C#, you just specify the method name.

Mehrdad Afshari
Thanks! You're fast too!
A: 

you need to change it to: list.Sort(AddressOf Utility.CompareContactListsBySortOrder)

Joe Caffeine