What's the fastest/easiest/best way to determine if a certain item exists
in a list?
(And what's the slowest/dumbest - I suppose that's enumerating the elements
and comparing each in turn in VB code?)
My collection can have up to a few thousand elements (each either a GUID or
an ID card number in "000-0000000-00" format) and an even larger number may
have to be checked, so speed does become a bit of an issue.
The shortest will be something like this, but how is the speed compared to
other methods?
Dim IDList As New Collection
IDList.Add(Nothing, "a")
IDList.Add(Nothing, "b")
IDList.Add(Nothing, "c")
Public Function Exists(ID As String) As Boolean
Try
Dim Dummy As Object = IDList.Item(ID)
Return True
Catch
Return False
End Try
End Function