我似乎无法弄清楚如何使用锯齿状数组和文件。我有三个带有数字的文件,并且想将每个文件读入它自己的数组中。这就是我到目前为止所拥有的。试图填充 [0] 数组但无济于事。任何帮助表示赞赏。也找不到任何关于这样做的教程。
private void button1_Click(object sender, EventArgs e)
{
StreamWriter section1;
StreamWriter section2;
StreamWriter section3;
StreamReader section1read;
StreamReader section2read;
StreamReader section3read;
section1 = File.CreateText("Section1.txt");
section2 = File.CreateText("Section2.txt");
section3 = File.CreateText("Section3.txt");
int[][] Scores = new int[3][];
Random randnum = new Random();
for (int i = 0; i < 12; ++i)
{
int num = randnum.Next(55, 99);
section1.WriteLine(num);
}
for (int j = 0; j < 8; ++j)
{
int num1 = randnum.Next(55, 99);
section2.WriteLine(num1);
}
for (int k = 0; k < 10; ++k)
{
int num3 = randnum.Next(55, 99);
section3.WriteLine(num3);
}
section1.Close();
section2.Close();
section3.Close();
section1read = File.OpenText("Section1.txt");
int nums = 0;
while (!section1read.EndOfStream)
{
Scores[0][nums] = int.Parse(section1read.ReadLine());
++nums;
}
for (int i = 0; i < Scores.Length; ++i)
{
listBox1.Items.Add(Scores[0][i]);
}
section1read.Close();
}