C#C
C#2y ago
Array

Reading in a File C# 2D arrays

I have to code a program that will read in a 2D array of 9 x 9 integers from a file that represents a Sudoku board solution

My goals are to
  1. Read in the file and display it on the form (it is a text file)
  2. After this, I have to write a validator for the solution
Right now, I’m focusing on part 1 which is reading in the file


Usually, the goal when reading in a file is to do the following
(Writing code to select the file)
  1. OpenFileDialog oFD = new OpenFileDialog();
  2. if (oFD.ShowDialog() == DialogResult.OK)
    (File selected so open to read it)
  3. StreamReader oSR = new StreamReader(oFD.OpenFile());
  4. int Records = int.Parse(oSR.ReadLine());
    (Initializing the arrays)
  5. Set array = new int [Records];
  6. for (int i = 0; i < array.length; i++)
    Array[i] = int.Parse(oSR.ReadLine());
    This is the procedure I usually go through to read in a file
My issue is since this is a 2D array, I get the error cannot implicitly

(My code for this 2D array, I get an error when setting SudokuBoard to Records): https://paste.mod.gg/ttybylvutrvb/0

https://paste.mod.gg/gokonoflypqv/0( here is how I normally code it in)

Anyone have ideas on how I code it in to read in the file?
IMG_4356.png
IMG_4358.png
A tool for sharing your source code with the world!
A tool for sharing your source code with the world!
Was this page helpful?