Question:You create an instance of the SortedList collection, as shown here:
Dim sl As New SortedList(Of Product, string)()
Which declaration of the Product class works correctly? - VB.NET
A Public Class Product
Implements IComparable
Public productName As String
Public Sub New(ByVal _productName As String)
Me.productName = _productName
End Sub
Public Function CompareTo(ByVal obj As Object) As Integer _
Implements System.IComparable.CompareTo
Dim otherProduct As Product = DirectCast(obj, Product)
Return Me.productName.CompareTo(otherProduct.productName)
End Function
B Public Class Product
Public productName As String
Public Sub New(ByVal _productName As String)
Me.productName = _productName
End Sub
Public Function CompareTo(ByVal obj As Object) As Integer _
Implements System.IComparable.CompareTo
Dim otherProduct As Product = DirectCast(obj, Product)
Return Me.productName.CompareTo(otherProduct.productName)
End Function
End Class
C Public Class Product
Implements IEquatable
Public productName As String
Public Sub New(ByVal _productName As String)
Me.productName = _productName
End Sub
Public Function Equals(ByVal obj As Object) As Integer _
Implements System.IEquatable.Equals
Dim otherProduct As Product = DirectCast(obj, Product)
Return Me.productName.Equals(otherProduct.productName)
End Function
End Class
D Public Class Product
Public productName As String
Public Sub New(ByVal _productName As String)
Me.productName = _productName
End Sub
Public Function Equals(ByVal obj As Object) As Integer
Dim otherProduct As Product = DirectCast(obj, Product)
Return Me.productName.Equals(otherProduct.productName)
End Function
End Class