[Mono-dev] String.GetHashCode on Mac

Bill Holmes billholmes54 at gmail.com
Tue Dec 2 11:07:41 EST 2008


David,

We may have hit this before.  See
http://www.nabble.com/String.GetHashCode-Discussion.-to18496625ef1367.html#a18496625

I lost tack of this issue after that thread but maybe it will help
someone else remember.

-bill

On Mon, Dec 1, 2008 at 9:25 AM, David Suarez
<listasdavid at codicesoftware.com> wrote:
> Hi,
>
> 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"
>        };
>
>        [STAThread]
>        static void Main(string[] args)
>        {
>            foreach (string s in testStrings2) PrintHash(s,
> s.GetHashCode());
>        }
>
>        private static void PrintHash(string str, int hash)
>        {
>            Console.WriteLine("  hash [{1}] line: [{0}]", str,
>              hash.ToString("X8"));
>        }
>    }
> }
>
> 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?
>
> Thanks,
>
> David
>
> Is this happening to anybody else??
>
> _______________________________________________
> Mono-devel-list mailing list
> Mono-devel-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-devel-list
>


More information about the Mono-devel-list mailing list