Consider the following code:
byte[] bytes = new byte[] { 1, 2, 5, 0, 6 };
byte[] another = new byte[] { 1, 2, 5, 0, 6 };
Hashtable ht = new Hashtable();
ht.Add(bytes, "hi");
Assert.IsTrue(ht.ContainsKey(another));
Why does this assertion fail? Being an array of a primitive type shouldn’t use using the object reference, should it? So why would it return false? Is there anything I can do to make this hashtable work?
Here’s a sample implementation:
You should use a stronger hash if you put thousands of arrays in the hash table. Check this post for an example.