Array Equality

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Tony Nassar

    #1

    Array Equality

    Hello, all!

    There's no documentation of an overriden Equals() method for arrays, and
    there does not seem to be one in fact, since any of these assertions will
    crash:
    int[] x = { 0, 1 };
    int[] y = { 0, 1 };

    // System.Diagnost ics.Debug.Asser t(x == y, "Arrays equal?");
    // System.Diagnost ics.Debug.Asser t(Array.Equals( x, y), "Arrays equal?");
    // System.Diagnost ics.Debug.Asser t(x.Equals(y), "Arrays equal?");

    Obviously I can loop through them, but do I have to?



    Tony Nassar
    The Analysis Corp.
    703-208-9630




  • Jon Skeet [C# MVP]

    #2
    Re: Array Equality

    Tony Nassar <tnassar@theana lysiscorp.com> wrote:[color=blue]
    > There's no documentation of an overriden Equals() method for arrays, and
    > there does not seem to be one in fact, since any of these assertions will
    > crash:
    > int[] x = { 0, 1 };
    > int[] y = { 0, 1 };
    >
    > // System.Diagnost ics.Debug.Asser t(x == y, "Arrays equal?");
    > // System.Diagnost ics.Debug.Asser t(Array.Equals( x, y), "Arrays equal?");
    > // System.Diagnost ics.Debug.Asser t(x.Equals(y), "Arrays equal?");
    >
    > Obviously I can loop through them, but do I have to?[/color]

    Yes, I believe you do.

    --
    Jon Skeet - <skeet@pobox.co m>
    Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

    If replying to the group, please do not mail me too

    Comment

    • Tony Nassar

      #3
      Re: Array Equality

      Oh, I know I do; don't worry about that. But I must say, it's peculiar that
      the '==' operator returns 'false' in this case! A "not implemented
      exception" I could understand, but 'false'?


      Comment

      • Jon Skeet [C# MVP]

        #4
        Re: Array Equality

        Tony Nassar <tnassar@theana lysiscorp.com> wrote:[color=blue]
        > Oh, I know I do; don't worry about that. But I must say, it's peculiar that
        > the '==' operator returns 'false' in this case! A "not implemented
        > exception" I could understand, but 'false'?[/color]

        Why would it *not* return false? It's just using object==, which
        compares two references.

        --
        Jon Skeet - <skeet@pobox.co m>
        Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

        If replying to the group, please do not mail me too

        Comment

        Working...