Hello, I am creating a program that has a byte[] used as the key for a Dictionary class. The problem is best described with an example:
(C# example of problem)
I imagine the Dictionary is searching for the exact reference to the byte[] which was added to the Dictionary, and not just searching for a value match (which is what I want to do).
Thanks
(C# example of problem)
Code:
private Dictionary<byte[], string> dictionary;
public void Method1()
{
// Set up the dictionary
dictionary = new Dictionary<byte[], string>();
byte[] bytes1 = new byte[2] { 0, 0 };
byte[] bytes2 = new byte[2] { 0, 0 };
dictionary.Add(bytes1, "hello");
// Search with byte[] 1, the original byte[]
string result1 = dictionary[bytes1];
string result2 = getMethod(bytes1);
// Search with byte[] 2, the non-original one
// These throw errors specifying that the entry does not exist
string result3 = dictionary[bytes2];
string result4 = getMethod(bytes2);
}
private string getMethod(byte[] getBytes)
{
return dictionary[getBytes];
}
Thanks
Comment