I know that you can use Enumerable.SequenceEqual to check for equality. But a multidimensional array does not have such a method. Any suggestion on how to compare a 2 dimensional array?
Actual problem:
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;
}
All these properties are set in the constructor SudokuGrid. Thus, all these properties have private setters. I want to save it that way.
Now I am doing some tests with C # unit tests. I want to compare 2 Gridswith their values, not their references.
Since I install everything using private seters through the constructor. This equal override in the class SudokuGridis correct, but not what I need:
public bool Equals(SudokuGrid other)
{
if ((object)other == null) return false;
bool isEqual = true;
for (byte x = 0; x < this.Grid.GetLength(0); x++)
{
for (byte y = 0; y < this.Grid.GetLength(1); y++)
{
if (!this.Grid[x, y].Equals(other.Grid[x, y]))
{
isEqual = false;
}
}
}
return isEqual;
}
, , . , :
SudokuGrid actual = new SudokuGrid(2, 3);
:
SudokuGrid expected = new SudokuGrid(2, 3);
:
Field[,] expected = sudoku.Grid;
grid, , setter .
, , .
: