Re: Struct vs Class



Thanks Dave,

I do override Equals and GetHashcode already. I guess I'll change it
back to a class. Thank you for you feedback. From what I had read, I
thought this was the case.

As a newbie, I'm interested in how much boxing / unboxing will be going
on when I define a struct as opposed to a class. I've just got Jeffrey
Richter's CLR via C# which seems to show me how to determine this via
the IL Disassembler. Some investigations to be done!

Thanks.

John.

.



Relevant Pages

  • Re: Dictionary with object for key
    ... If you have to use the object instance itself as the key, then the next question is: do you want/expect for multiple instances of your key object to be considered the same key when the "name" field is the same? ... If so then one solution is to override Equals() and GetHashCodein your object's class. ... just call the appropriate method and GetHashCode()) on the field in the two objects. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Overriding Equals method
    ... Classes usually don't override Equals or GetHashCode. ... But I would think about why you want to use the Equals method before implementing your class as struct because ...
    (microsoft.public.dotnet.framework)
  • Re: Overriding operators
    ... For the record - there is a reason that the compiler warning prompts you to ... override Equals() and GetHashCode() - so you really should provide something ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Re:Object.Equals() and GethashCode()
    ... > if two object are deemed Equal then GetHashCode must return the same ... > value (the converse is not true). ... if you override Equals the ... you *can't* override Equals for mutable ...
    (microsoft.public.dotnet.languages.csharp)

Loading