GetHashCode

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
 
G

Guest

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
 
B

bart_deboeck

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top