Hello everyone!
If I have a list and want to search to see if it has a specific item in it, I use List.contains. However I found out that one cannot search for a custom made object. Why is this so? How can I fix it?
Thanks all,
~Nic
vb Code:
Option Strict On Option Explicit On Public Class Form1 Dim List1 As New List(Of ComplexObject) Private Sub ButtonAdd_Click(sender As Object, e As EventArgs) Handles ButtonAdd.Click With List1 .Add(New ComplexObject(New Point(5, 5), 10, "string1")) .Add(New ComplexObject(New Point(6, 10), 20, "string2")) .Add(New ComplexObject(New Point(8, 15), 30, "string3")) .Add(New ComplexObject(New Point(10, 20), 40, "string4")) End With MsgBox(List1.Count & " items on list.") End Sub Private Sub ButtonCheck_Click(sender As Object, e As EventArgs) Handles ButtonCheck.Click Dim N As New ComplexObject(New Point(8, 15), 30, "string3") If List1.Contains(N) Then MsgBox("Yes") Else MsgBox("No") End If End Sub Private Sub ButtonRemove_Click(sender As Object, e As EventArgs) Handles ButtonRemove.Click List1.Clear() MsgBox(List1.Count & " items on list.") End Sub End Class Public Class ComplexObject Dim P As Point Dim N As Int32 Dim S As String Public Sub New(P_New As Point, N_New As Int32, S_New As String) P = P_New N = N_New S = S_New End Sub End Class


Reply With Quote
