Re: Comparing Array Objects

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Alvin Bruney [MVP] (vapor)
Date: 02/24/04


Date: Tue, 24 Feb 2004 12:29:24 -0600


> However, on a side-note, when realizing a ValueType class, like a struct
in
> C#; forgetting to override Equals, GetHashCode and ToString should be a
> criminal offence. =)

No. not true at all.

An application even as gracious as the framework cannot uncover every
programmer's intent. In this regard, overriding must be a recommendation
albeit a strong one. But it cannot be manditory as in a criminal offense
which is what you are implying. Throughout the programming life cycle there
may be times when overriding is not needed even for valuetype classes. A
framework needs to be as flexible as possible which is why overriding is
always optional.

-- 
Regards,
Alvin Bruney [ASP.NET MVP]
Got tidbits? Get it here...
http://tinyurl.com/3he3b
"Michael S" <a@b.c> wrote in message
news:uWFhtFs%23DHA.2524@tk2msftngp13.phx.gbl...
>
> "Jon Skeet [C# MVP]" <skeet@pobox.com> wrote in message
> news:MPG.1aa3f876e1ef241798a1d6@msnews.microsoft.com...
> > Raphael Iloh <ilohraphael_NOSPAM@hotmail.com> wrote:
> > > ...thanks Alvin but your explanation falls short given the following
> > > example:
>
> > The real reason is that Array doesn't override the Equals method
> > (unlike, say, String).
>
> This is the real explaination. One should never assume that comparison are
> value-based. Hence that two different arrays are not equal, is working as
> designed.
>
> However, on a side-note, when realizing a ValueType class, like a struct
in
> C#; forgetting to override Equals, GetHashCode and ToString should be a
> criminal offence. =)
>
> - Michael S
>
> ps.
>  Keep up the good work Skeet. I like you posts....
>
>


Relevant Pages

  • RE: Equality vs Sameness
    ... > Good call on my misuse of overriding vs overloading. ... So you override Equals and GetHashCode even for forms, ... or wanted to compare two instances of a singleton? ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: override GetHashCode
    ... "Stoyan" wrote in message ... > "Derived classes that override GetHashCode must also override Equals to ... > Does any one know, why we must also override Equals, ...
    (microsoft.public.dotnet.framework)
  • Re: do I need to override the equals() method?
    ... be able to compare two objects of my class i.e. to check if they are ... you might want to override equals. ... otherwise some of the standard collections ...
    (comp.lang.java.programmer)
  • Re: Ensuring a method is overridden
    ... proxy to ensure toString, equals, hashCode, etc. are overridden: ... protected abstract String abString; ... Not much else makes sense to override.) ...
    (comp.lang.java.programmer)
  • Re: ToString - meaningful Vs. Useless
    ... ToString method is overridden in a class, the developer that overrides it ... such as the override of ToString on Enums that displays the token of the ... "ToString" from the Object class. ...
    (microsoft.public.dotnet.general)