C#读取txt数据到一个二维数组
private void button1_Click(object sender, EventArgs e) { if (openFileDialog1.ShowDialog() != DialogResult.Cancel) { FileName = openFileDialog1.FileName; System.IO.StreamReader readfile = new System.IO.StreamReader(FileName); readfile.BaseStream.Seek(0, System.IO.SeekOrigin.Begin); int line_total=0;//总行数 while (readfile.ReadLine() != null) { line_total++; } textBox3.Text = line_total.ToString(); readfile.BaseStream.Seek(0,System.IO.SeekOrigin.Begin); // string line = readfile.ReadLine(); List<string[]> list = new List<string[]>(); while (!readfile.EndOfStream) { string[] line = readfile.ReadLine().Split(' '); string[] arr = new string[line.Length]; for (int i = 0; i < line.Length; i++) { arr[i] = Convert.ToString(line[i]); } list.Add(arr); } string[][] shuzu = list.ToArray(); textBox4.Text = shuzu[0][5]; //显示指定数据,此程序不能用shuzu[0,5],还没搞懂原因 } else return; }