title: How to compare multidimensional arrays on equality?
body: <p>I know you can use <a href="http://msdn.microsoft.com/en-us/library/bb348567.aspx" rel="nofollow">Enumerable.SequenceEqual</a> to check equality. But a multidimensional array does not have such method. <em>Any suggestion on how to compare 2 dimensional array?</em> </p>
  
  <p><strong>Actual problem:</strong></p>
  
  <pre><code>public class SudokuGrid
  {
      public Field[,] Grid
      {
          get { return grid; }
          private set { grid = value; }
      }
  }
  
  public class Field
  {
      private byte digit;
      private bool isReadOnly;
      private Coordinate coordinate;
      private Field previousField;
      private Field nextField;
  }
  </code></pre>
  
  <p>All those properties are set in the <code>SudokuGrid</code> constructor. So all those properties have <strong>private</strong> setters. I want to keep it that way.</p>
  
  <p>Now, I'm doing some tests with C# unit tests. I want to compare 2 <code>Grids</code> on their values rather then their references.</p>
  
  <p>Since I set everything with private setters through constructor. This Equal override in class <code>SudokuGrid</code> is correct, but not what I need:</p>
  
  <pre><code>public bool Equals(SudokuGrid other)
  {
      if ((object)other == null) return false;
  
      bool isEqual = true;
  
      for (byte x = 0; x &lt; this.Grid.GetLength(0); x++) // 0 represents the 1st dimensional array
      {
          for (byte y = 0; y &lt; this.Grid.GetLength(1); y++) // 1 represents the 2nd dimensional array
          {
              if (!this.Grid[x, y].Equals(other.Grid[x, y]))
              {
                  isEqual = false;
              }
          }
      }
  
      return isEqual;
  }
  </code></pre>
  
  <p>It is not what I need since I'm doing testing. So if my actual sudoku is:</p>
  
  <pre><code>SudokuGrid actual = new SudokuGrid(2, 3);
  </code></pre>
  
  <p>then my expected sudoku can't just be:</p>
  
  <pre><code>SudokuGrid expected = new SudokuGrid(2, 3);
  </code></pre>
  
  <p>but should be:</p>
  
  <pre><code>Field[,] expected = sudoku.Grid;
  </code></pre>
  
  <p>So I can't use the class to compare it's grid property, since I can't just set the grid since setter is private.
  It would be stupid if I had to change my original code just so my unit testing could work.</p>
  
  <p><strong>Questions:</strong> </p>
  
  <ul>
  <li>So is their a way to actually compare multidimensional arrays? <em>(So can I maybe override the equal method an multidimensional array uses?)</em></li>
  <li>Is there maybe another way to solve my problem? </li>
  </ul>