views:

3236

answers:

2

I have a custom class set up as a key that has two properties, X and Y

I have something similar to this:

Dim test As New List(of TestClass)
Dim key as New TestData

key._a = A
key._b = B

For Each a As TestClass In SomeCollection
  If Not test.Contains(key) Then
     'Do Stuff
  End If
Next

My question is this: How does the .Contains on the List(of T) behave? Does it look for an identical data structure, or does it simply match on one of the properties of my key?

If you can, please include a link where I can look at some documentation regarding this.

EDIT Is the Contains method Typesafe?

+2  A: 

It uses the Equals method to check for identity.

By default (if not overridden) Equals returns true if two references are identical or two structures are equal memberwise.

Mehrdad Afshari
+1  A: 

I just asked the same question yesterday :)

Your TestClass should implement IEquatable(of T) http://msdn.microsoft.com/en-us/library/ms131187(VS.80).aspx interface to make it type safe

roman m