I have two objects that are derived from same the base class.
Lets say ObjA is the base class, and ClassB and ClassC inherits ObjA.
If I have a
dim lst1 as List(Of ClassB)
dim list2 as List(Of ClassA)
and and I want to check for the existence of something being in lst1 that it is in list2, now I am only interested in comparing against one key bit of information that it is declared in the base class and is a string.
How can I iterate through the lst1 comparing against list2? I thought I could I overload/override the Equals method but I am having no joy for either of the classes and say some thing similar to
Public Overloads Overrides Function Equals(ByVal obj As Object) As Boolean
Dim temp As ClassA = TryCast(obj, ClassA)
If temp.Id = Me.Id Then
Return True
Else
Return False
End If
End Function
But this doesn't seem to work.
EDIT: Further clarification. If I call
lst1.contains(instance of ClassA)
This throws an error as it (rightly) expects to get a instance of ClassB.