索引超出了数组界限问题。
namespace _0ne{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();//窗口初始化
}
private void button1_Click(object sender, EventArgs e)
{
string[,] str = new string[2, 3];
StreamReader sr = File.OpenText("C:\\Users\\Administrator\\Desktop\\myy.txt");
int k = 0;//当前读取的是第几行
while (sr.Peek() != -1)
{
str[k % 2, k % 2] = sr.ReadLine();
k++;
}
for (int i = 1; i <=3; i++)
{
string controlName1 = string.Format("textBox1{0}", i);
string controlName2 = string.Format("textBox1{0}", i);
(Controls.Find(controlName1, false)[0]).Text = str[0, i-1];/////为什么这里总是报出索引超出了数组界限。???这是为什么
(Controls.Find(controlName2, false)[0]).Text = str[1, i-1];
}
sr.Close();
}