public partial class Form1 : Form
{
public List<TextBox> textBoxInputList;
public void Form1_Load(object sender, EventArgs e)
{
List<TextBox> textBoxInputList = new List<TextBox>() {textBox1};
}
private void ButtonCleanInput_Click(object sender, EventArgs e)
{
List<TextBox> textBoxInputList = new List<TextBox>() {textBox1};
//在这里还要再实例化一次textBoxInputList
}
}
已经设置为public List,在方法Form-load使用textBoxInputList没问题,但是在别的方法里,比如在方法ButtonCleanInput-Click,必须重写
List<TextBox> textBoxInputList = new List<TextBox>() {textBox1};
否则textBoxInputList里面是空的,报错如下
请问如何new 一个
List<TextBox> textBoxInputList
,然后在别的方法里都能调用?
编程新手,不懂轻喷