✅ Dictionary not returning Value
HashCode keys are the same however its for some reason not returning the value from the dictionary
Pathfinding Class
15 Replies
Panel Grid Class/Dictionary Creation
PathNode getNode Function
Debug Output
Error Output
what is the definition of
panelTuple
?Panel Tuple Class
you don't have an equality implementation defined
https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.dictionary-2?view=net-8.0#remarks
oh....
more reading now to do 😦
a hash code isn't guaranteed to be unique to a particular object, it's just used to store/find values more efficiently
2 different objects could have the same hash code
also, your object should be immutable because as it is now you could modify x and y
the simplest solution is to use a record instead of writing a class yourself, it implements value-type semantics for you
im so confused cuz im quite new to dictionaries....would you be able to walk me through it?
basically, the dictionary uses the hash to store items in one of several "buckets"
then when you look up a key, it computes the hash code of the key to find the same bucket the object should be stored in
but the buckets can hold more than one item, so there is still an element of looping over that bucket and checking if the key is really there
oh yea i know what the dictionary does and how it get values, im just not sure about this IEquality thingy
how do i implement that?
implement
System.IEquatable<T>
for a case like this you'd check if the x and y of both arguments are equaldont know how to implement that
your IDE will prompt you if you specify the interface on your type
also, if you look it up you'll see docs
i have no idea what to do lol
do i chuck this in the panelTuple Class?
I have no idea what im doing
Yep I got it now. Much more simple than the docs showed it to be. Thank you for your help!
Just gotta wait for the battery to recharge now so I can see it in action 😂