0

I was trying to make a dictionary but as a key it would use pair of integers.

public Dictionary<int[], car> listOfCells = new Dictionary<int[], car>();

but when i check if there is a value it always returns false

return listOfCells.ContainsKey(new int[] { x, y })
Aes123
  • 85
  • 6
  • you should create dictionary in such a way `public Dictionary listOfCells = new Dictionary();` where key will be some unique identifier for the car – Vivek Nuna Feb 27 '21 at 08:11

1 Answers1

0

Arrays are reference types. Thus, two arrays having the same contents have two different object identities and are not "equal".

If all your arrays have a constant number of elements (for example, if you use the array to store 2D coordinates), consider using a value tuple instead:

public Dictionary<(int, int), car> listOfCells = new Dictionary<(int, int), car>();
Heinzi
  • 167,459
  • 57
  • 363
  • 519