在类定义中
public String[,] Sodoku_Gri = new String [9, 9];
public void populate_grid_by_file()
{
TextReader tr = new StreamReader("data.txt");
// read a line of text
String store_data_from_file = tr.ReadLine();
for (int i = 0; i < Sodoku_Gri.GetLength(0); i++)
{
for (int j = 0; j < Sodoku_Gri.GetLength(1); j++)
{
Sodoku_Gri[i, j] = __________??
}
}
tr.Close();
}
在data.txt里面写着“1--2--3--3-4-4-5---7-3-4---7--5--3-6--7-- -4--3-2--4-5-------3--2-6--7---4---4--3-" 我必须从文件中读取它并将它们放在 C# 中的二维数组中!在 C++ 中很容易。我是初学者!在 C++ 中,我们也应该在字符串中进行索引以访问字符串中的每个字符!我可以在我的二维数组中写入这些数据吗?这样 Sodoku_Grid[9,9] 中的 81 个空格都被文件中的数据填充了!