✅ HashCode returning different numbers when parsing the same value
I pass 0, 420 into HashCode.Combine, but when they are in different files the hashcode does not return the same number back
21 Replies
check the spaces and returns first
thats the outputs im getting
yeah, that's strange
but that does not relate to the files
i get different numbers each time, too
well, they certainly will be different each time you run the program. the initial state used by the hashcode algorithm is randomly generated when .NET is loaded
reflectronic
REPL Result: Success
Result: <>f__AnonymousType0#1<int, int, int>
Compile: 229.787ms | Execution: 54.598ms | React with ❌ to remove this embed.
it's definitely supposed to be the same every time within the same process, though
got it
thx
I know it changes each time the program but it should be the same hashcode in the program
Where i call the pathfinding
Create Tuple
the only explanation for HashCode.Combine returning different values for the same objects is that you are not using the same objects
different variables holding the same number would give a different hashcode?
are you sure it's the same number
i trust that HashCode works properly tbh. it is very unlikely that the problem is with HashCode
startX and startY is the first 2
its pissing me off lol
right, and what does
findPath
do with startPointX
and startPointY
ah. i see the issue
int x = 420;
and double x = 420;
will not have the same hash code
HashCode.Combine(0,420)
passes int
s, while your parameters are all double
s
you should try HashCode.Combine(0.0,420.0)
(or 0d, 420d
, it's the same)where is that
Debug.WriteLine("Inside FindPath Class: " + HashCode.Combine(0,420).GetHashCode());
System.Collections.Generic.KeyNotFoundException: 'The given key 'Birds_Eye.Views.Resources.Functions.panelTuple' was not present in the dictionary.'
i am not sure what you did tbh because changing the debug print statement should not have changed that code at all
shall i make the github project public so you can see everything?
to be clear, you do not have a problem with your hash codes
you think you have a problem with your hash codes because you printed out
HashCode.Combine(0, 420)
trying to look for an issue
when you really should have printed out HashCode.Combine(0.0, 420.0)
--since these are the values you're actually using--and that would have shown you that there's no issue, and the hash codes are the same everywhere
i do not know why you started doing this. presumably, you have some other issue that you're trying to debug? if so, i am sorry but this isn't what's causing it
if you're trying to figure out some other issue--maybe you are having problems with your dictionary--i am happy to help