GetHashCode

  • Thread starter Thread starter perspolis
  • Start date Start date
P

perspolis

Hi
I have a question about GetHashCode for strings.
Is it unique for all string in diffrent OS?
for example "test".GetHashCode () is the same for all of OS?
thanks in advance
 
Is it unique for all string in diffrent OS?

FWIW, hash codes aren't meant to be unique.
for example "test".GetHashCode () is the same for all of OS?

No there's no such guarantee. In practice it probably will be as long as
you're running the same CLI implementation (such as Microsoft's CLR) but if
you care about portability you shouldn't assume that to be the case.


Mattias
 
Hi,

The String.GetHashCode documentation :

The behavior of GetHashCode is dependent on its implementation, which
might change from one version of the common language runtime to
another. A reason why this might happen is to improve the performance
of GetHashCode. If you require the behavior of GetHashCode be constant,
override the runtime implementation of GetHashCode with an
implementation of your own that you know will never change.

so, it seems reasonable to expect that it is not the same for all OS's
since different runtimes are used on each OS.

Succes,
Bart
 
Back
Top