[Mono-dev] String.GetHashCode on Mac

David Suarez listasdavid at codicesoftware.com
Mon Dec 1 09:25:46 EST 2008


I've run into a problem with the String.GetHashCode method in macosx 
(10.5.3, intel). The point is I get the same hashcode for very different 
strings, apparently only taking into account the last 7 chars of the 
string. This happens with mono 2.0 installer.

Consider this test case:

using System;

namespace hashtest
    class Class2
         private static string[] testStrings2 = new string[]
            "something to worry about",
            "ing to worry about",
            "to worry about",
            "orry about",
            "y about",
            " about"

        static void Main(string[] args)
            foreach (string s in testStrings2) PrintHash(s, 

        private static void PrintHash(string str, int hash)
            Console.WriteLine("  hash [{1}] line: [{0}]", str,

Running on mac, I get this result:

  hash [9DA57994] line: [something to worry about]
  hash [9DA57994] line: [ing to worry about]
  hash [9DA57994] line: [to worry about]
  hash [9DA57994] line: [orry about]
  hash [9DA57994] line: [y about]
  hash [1DA57994] line: [ about]

It seems to me that the String.GetHashCode in String.cs is not getting 
called, because this method works fine (I tested separately). Is this 
happening to anybody else? Any clue on what code is being called on the 
mac for getting the hash code of strings?



Is this happening to anybody else??

More information about the Mono-devel-list mailing list