Hash ContainsValue?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a very simple class (see CurrentUser below), that I am adding to a
hash table.

Public Class CurrentUser
Private userName As String
Private sessionId As String
Private logindateTime As DateTime
'Properties left out
End Class

I add the values:
myHash(somekey,CurrentUser)

I am implementing ICollection and everything works fine, except the
ContainsValue.
Public Function ContainsValue(ByVal value As CurrentUser) As Boolean
Return m_HashTable.ContainsValue(value)
End Function
I have also tried -
Public Function ContainsValue(ByVal value As CurrentUser) As Boolean
Return m_HashTable.ContainsValue(value.Name)
End Function

Questions:
What do I need to do to get my ContainsValue to work properly?
 
ContainsValue method of the hashtable uses objects Equals() method.

To solve the problem you need to override Equals method in your class...

I do not know VB too good, but also why wouldn't you specify ByRef in your
functions declarations?
 
Back
Top