Click to See Complete Forum and Search --> : [RESOLVED] Uri.GetHashCode Unique?


Chen.Fisher
March 14th, 2007, 05:16 AM
Hi,

Is the hashcode produced by the function Uri.GetHashCode unique? Can two different URIs produce the same hashcode?

A quote from Object.GetHashCode:
The default implementation of GetHashCode does not guarantee uniqueness or consistency

I would like to use the value of Uri.GetHashCode as a unique key in my DB and i have to be sure it is unique.

If you have a link to an article claiming it is unique, please refer me to it.

Thanks,
Chen.

Zaccheus
March 14th, 2007, 09:13 AM
Hash codes are generally not guaranteed to be unique.

To see why, have a look at:
http://blogs.msdn.com/tomarcher/archive/2006/05/10/594204.aspx

The number of possible URLs if far bigger than the number of possible hash codes returned by the .net method.

Chen.Fisher
March 14th, 2007, 12:08 PM
Thanks, Zaccheus.

That was a good article.