I don't like the use orof row and column in Validate and that is not really what it is
Not as cool as your code but a little more compact
public class Sudoku2
{
byte[,] gridy = new byte[9, 9] { { 0, 0, 0, 1, 4, 0, 0, 2, 0 },
{ 0, 0, 6, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 6, 0, 0, 0 },
{ 0, 0, 1, 0, 0, 0, 0, 0, 0 },
{ 0, 6, 7, 0, 0, 0, 0, 0, 9 },
{ 0, 0, 0, 0, 0, 0, 8, 1, 0 },
{ 0, 3, 0, 0, 0, 0, 0, 0, 6 },
{ 5, 0, 0, 0, 0, 7, 0, 0, 0 },
{ 0, 0, 0, 5, 0, 0, 0, 7, 0 },
};
public bool Validate(byte[,] grid)
{
for (int i = 0; i < 9; i++)
{
bool[] row = new bool[10];
bool[] col = new bool[10];
for (int j = 0; j < 9; j++)
{
if(row[grid[i,j]] & grid[i, j] > 0)
{
return false;
}
row[grid[i, j]] = true;
if (col[grid[j, i]] & grid[j, i] > 0)
{
return false;
}
col[grid[j, i]] = true;
if ((i + 3) % 3 == 0 && (j + 3) % 3 == 0)
{
bool[] sqr = new bool[10];
for (int m = i; m < i + 3; m++)
{
for (int n = j; n < j + 3; n++)
{
if (sqr[grid[m, n]] & grid[m, n] > 0)
{
return false;
}
sqr[grid[m, n]] = true;
}
}
}
}
}
return true;
}
public Sudoku2()
{
bool good = Validate(gridy);
}
public Sudoku2(byte[,] grid)
{
bool good = Validate(grid);
}
}