[Mono-list] mcs compiles on linux. Now what?

Dan Lewis dihlewis@yahoo.co.uk
Fri, 8 Mar 2002 14:00:48 +0000 (GMT)

 --- Piers Haken <piersh@friskit.com> wrote:
> I'm
> not sure what Object's GetHashCode() does. I'll look into it. I have a
> feeling it's internal, though.

It's linked in with the GC system. From the System.Object documentation:

"The default implementation returns an index for the object determined by the
common language runtime. The index is unique to an instance of an object within
an AppDomain for an instance of the executing engine. However, because this
index can be reused after the object is reclaimed during garbage collection, it
is possible to obtain the same hash code for two different objects."

Now try this:

using System;

public class HashCodeTest {
	public static void Main (string[] args) {
		int [] hash = new int [4];
		hash [0] = new X ().GetHashCode ();
		hash [1] = new X ().GetHashCode ();

		using (X x = new X ()) {
			hash [2] = x.GetHashCode ();
		GC.Collect ();
		hash [3] = new X ().GetHashCode ();

		foreach (int h in hash)
			Console.WriteLine (h);

class X : IDisposable {
	public void Dispose () { }

And you'll get:


But for our purposes at the moment, the pointer implementation would seem fine.


Do You Yahoo!?
Everything you'll ever need on one web page
from News and Sport to Email and Music Charts