Sudoku.Sudoku.ToString C# (CSharp) Method

ToString() static private method

static private ToString ( int sudoku ) : string
sudoku int
return string
        static string ToString(int[,] sudoku)
        {
            var sb = new StringBuilder();
            for (int i = 0; i < BOARD_SIZE; i++)
            {
                for (int j = 0; j < BOARD_SIZE; j++)
                {
                    sb.Append(sudoku[i, j] + " ");
                }
                sb.Append('\n');
            }
            sb.Append('\n');
            return sb.ToString();
        }

Usage Example

コード例 #1
0
ファイル: UnitTest.cs プロジェクト: dixitsandeep/sudoku
        public void SolveAFile(string filePath)
        {
            string line;

            System.IO.StreamReader file =
                new System.IO.StreamReader(filePath);

            int currentLineIndex = 0;

            while ((line = file.ReadLine()) != null)
            {
                string[] sudokulineElements = line.Split(',');

                string inputProblem     = sudokulineElements[0];
                string expectedSolution = sudokulineElements[1];


                Sudoku.Sudoku sudoku = new Sudoku.Sudoku(inputProblem);



                //RenderNewEntries(sudoku, Color.Black);

                //MessageBox.Show($"Problem {counter} loaded from DB. Click to Solve ");

                bool   isSovled = sudoku.Solve();
                string solution = sudoku.ToString();

                if (isSovled)
                {
                    if (!solution.Equals(expectedSolution))
                    {
                        throw new Exception($"Sudoku solution does not match input solution excped: {expectedSolution}.\n Actual {solution}");
                    }
                    Console.WriteLine("Solved a Problem. Rating=" + sudoku.DifficultyRating);
                }
                else
                {
                    throw new Exception($"Sudoku could not be solved. Incompelete solution is {solution} expected solution was {expectedSolution}");
                }



                currentLineIndex++;
            }

            file.Close();
        }
All Usage Examples Of Sudoku.Sudoku::ToString