Re: [ADVANCED-DOTNET] GetHashCode() method

2005-07-05 Thread Keith Hill
I'm envisioning a nice little skit that a Don Box or someone like that could pull off on stage. Don't worry there are no bath-tubs or naked presenters involved. It is along the lines of the typical malevolent computer/robot on StarTrek that is defeated by a paradoxical question. In this case,

Re: [ADVANCED-DOTNET] GetHashCode() method

2005-07-03 Thread J. Merrill
The URL you referenced says [quote] WARNING: When an object is stored in a hash table, an application should never change the object in a way that will change its hash code. If you do so, the object will thenceforth be in the wrong bucket. [end quote] I fear that MS did not make it clear enough

Re: [ADVANCED-DOTNET] GetHashCode() method

2005-07-03 Thread JimK
to the object. - Jim -Original Message- From: Unmoderated discussion of advanced .NET topics. [mailto:[EMAIL PROTECTED] On Behalf Of Ian Griffiths Sent: Saturday, July 02, 2005 2:47 AM To: ADVANCED-DOTNET@DISCUSS.DEVELOP.COM Subject: Re: [ADVANCED-DOTNET] GetHashCode() method > special cod

Re: [ADVANCED-DOTNET] GetHashCode() method

2005-07-02 Thread J. Merrill
At 05:47 AM 7/2/2005, Ian Griffiths wrote >> special code needs to exist to ensure that once GetHashCode() >> has returned a value, that object instance must always return >> the same value from later GetHashCode calls. > >Nope. I know the docs say that GetHashCode must always return the same >val

Re: [ADVANCED-DOTNET] GetHashCode() method

2005-07-02 Thread Philip Nelson
ny object > that's in use as a key.) > > > So if you want to write mutable objects that implement GetHashCode you > have two choices. (1) your GetHashCode could return a constant value, > the same for all instances regardless of value, or (2) your object's > hash code

Re: [ADVANCED-DOTNET] GetHashCode() method

2005-07-02 Thread Ian Griffiths
ject's hash code must change when the value changes in a way that affects the outcome of Equals. -- Ian Griffiths http://www.interact-sw.co.uk/iangblog/ > -Original Message- > From: Unmoderated discussion of advanced .NET topics. [mailto:ADVANCED- > [EMAIL PROTECTED] On Behalf Of J. Me

Re: [ADVANCED-DOTNET] GetHashCode() method

2005-06-27 Thread Frans Bouma
> You can get dupes with GetHashCode(); but two objects with > the same "value" must have the same hash code. > I'll admit that Equals() must be overridden when > GetHashCode() is overridden; but, I disagree that > GetHashCode() is used wherever Equals() is used. Heh I agree, though I thin

Re: [ADVANCED-DOTNET] GetHashCode() method

2005-06-27 Thread Frans Bouma
> At 02:49 PM 6/27/2005, Frans Bouma wrote (in part) > >> There's been some discussion lately regarding the > >> Object.GetHashCode() method. > >> > >> I think the concensus is pretty clear: for best > reliability, classes > >> that implement GetHashCode() should be immutable. > > > >Why? y

Re: [ADVANCED-DOTNET] GetHashCode() method

2005-06-27 Thread Bogdan Lachendro
On 2005-06-27 21:19, Peter Ritchie wrote: Hashtable.ContainsKey is basically looping until (entry.key.GetHashCode() == keyParameter.GetHashCode() && entry.key.Equals(keyParameter)) == true. To be clear: The hashtable actually uses a bit different algorithm. The hash code is used to determine t

Re: [ADVANCED-DOTNET] GetHashCode() method

2005-06-27 Thread Peter Ritchie
See comments below. On Mon, 27 Jun 2005 15:37:18 -0400, J. Merrill <[EMAIL PROTECTED]> wrote: >I think the right way to say it is that if the GetHashCode result >is computed from values of one or more properties (or fields) of >the object, those values must be immutable -- either that, or special

Re: [ADVANCED-DOTNET] GetHashCode() method

2005-06-27 Thread Peter Ritchie
You can get dupes with GetHashCode(); but two objects with the same "value" must have the same hash code. I'll admit that Equals() must be overridden when GetHashCode() is overridden; but, I disagree that GetHashCode() is used wherever Equals() is used. As with any hash, objects of save "value" *

Re: [ADVANCED-DOTNET] GetHashCode() method

2005-06-27 Thread J. Merrill
At 02:49 PM 6/27/2005, Frans Bouma wrote (in part) >> There's been some discussion lately regarding the >> Object.GetHashCode() method. >> >> I think the concensus is pretty clear: for best reliability, >> classes that implement GetHashCode() should be immutable. > >Why? you can also get du

Re: [ADVANCED-DOTNET] GetHashCode() method

2005-06-27 Thread Frans Bouma
> There's been some discussion lately regarding the > Object.GetHashCode() method. > > I think the concensus is pretty clear: for best reliability, > classes that implement GetHashCode() should be immutable. Why? you can also get dupes with GetHashCode. It's not as if it's a magic value.

[ADVANCED-DOTNET] GetHashCode() method

2005-06-27 Thread Peter Ritchie
There's been some discussion lately regarding the Object.GetHashCode() method. I think the concensus is pretty clear: for best reliability, classes that implement GetHashCode() should be immutable. Other than the Hashtable and ProperytCollection classes, does anyone know where GetHashCode() is us