初学C# ,有关9×9宫格行列检验问题
我初始了一个9×9宫格(x,y是lable坐标),行符合数独规则(1~9不重复),但是怎么检验列呢?我的想法是遍历之前有的数字。如果不一样就继续检验,如果一样就重新随机个数字再从头开始重新检验。但是不知道怎么写,或者有没有更好的方法呢?谢谢!程序代码:
public Form1() { InitializeComponent(); Label[,] sudoku = new Label[9, 9]; Random rd = new Random(); string[] index = new string[9]; int y = 25; for (int i = 0; i < 9; i++) { for (int k = 0; k < 9; k++) { index[k] = (k + 1).ToString(); } int size = 9; int x = 98; for (int j = 0; j < 9; j++) { int number = rd.Next(0, size - 1); sudoku[i, j] = new System.Windows.Forms.Label(); sudoku[i, j].Location = new System.Drawing.Point(x, y); sudoku[i, j].BackColor = System.Drawing.Color.DarkGray; sudoku[i, j].Size = new System.Drawing.Size(30, 30); sudoku[i, j].BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D; sudoku[i, j].Font = new System.Drawing.Font("Verdana", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); sudoku[i, j].TextAlign = System.Drawing.ContentAlignment.MiddleCenter; sudoku[i, j].Text = index[number]; Controls.Add(sudoku[i, j]); index[number] = index[size - 1]; size--; x = x + 30; } y = y + 30; } }