M
Mike
Hi. I have the class below that implements the ICollection(Of Object). My
problem is that I can't seem to build an efficient Contains() method. My
Contins() method logic requires an exception in order to identify that an
item doesn't exist. Is there a better way to program this so I don't have to
catch an exception? Thanks.
Public MustInherit Class AbstractCol
Implements ICollection(Of Object)
Protected _Collection as Collection
Public Function Contains(ByVal item as Object) Boolean Implements
System.Collection.Generic.ICollection(Of Object).Contains
Try
If Not _Col.Items(item) Is Nothing Then Return True
' you would think the above Is Nothing check would prevent an
exception but it doesn't
Catch
' This happens if the item doesn't exist.
Return False
End Try
End Sub
End Class
problem is that I can't seem to build an efficient Contains() method. My
Contins() method logic requires an exception in order to identify that an
item doesn't exist. Is there a better way to program this so I don't have to
catch an exception? Thanks.
Public MustInherit Class AbstractCol
Implements ICollection(Of Object)
Protected _Collection as Collection
Public Function Contains(ByVal item as Object) Boolean Implements
System.Collection.Generic.ICollection(Of Object).Contains
Try
If Not _Col.Items(item) Is Nothing Then Return True
' you would think the above Is Nothing check would prevent an
exception but it doesn't
Catch
' This happens if the item doesn't exist.
Return False
End Try
End Sub
End Class