我正在开发一个 C# 应用程序,当加载表单时,我希望它读取 txt 文件的内容并将其存储到数组中。接下来,当单击表单上的按钮时,我希望按钮单击事件来访问数组。如何将数组传递给按钮单击事件?我下面的代码有一个错误“statusArray 在当前上下文中不存在”,并且与按钮单击事件中对数组的引用有关。我需要做什么?
苏珊
private void btnCompleted_Click(object sender, EventArgs e)
{
for (int i = 0; i < statusArray.Count; i++)
{
if (statusArray[i].Equals("Complete"))
lstReports.Items.Add(statusArray[i-2]);
}
}
private void Reports_Load(object sender, EventArgs e)
{
// declare variables
string inValue;
string data;
ArrayList statusArray = new ArrayList();
inFile = new StreamReader("percent.txt");
// Read each line from the text file
while ((inValue = inFile.ReadLine()) != null)
{
data = Convert.ToString(inValue);
statusArray.Add(inValue);
}
// Close the text file
inFile.Close();
}