I'm trying to use an int array as key in C# and the behaviour I'm seeing is unexpected (for me).
var result = new Dictionary<int[], int>();
result[new [] {1, 1}] = 100;
result[new [] {1, 1}] = 200;
Assert.AreEqual(1, result.Count); // false is 2
It seems the same with List too.
var result = new Dictionary<List<int>, int>();
result[new List<int> { 1, 1 }] = 100;
result[new List<int> { 1, 1 }] = 200;
Assert.AreEqual(1, result.Count); // false is 2
I'm expecting the Dictionary to use Equals to decide if a Key is present in the map. This doesn't seem to be the case.
Can someone explain why and how I can get this sort of behaviour to work?