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 }) 
1
  • you should create dictionary in such a way public Dictionary<int, int[]> listOfCells = new Dictionary<int, int[]>(); where key will be some unique identifier for the car Commented Feb 27, 2021 at 8:11

1 Answer 1

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>(); 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.