에로드 할 때 나는 폼이로드 될 때 txt 파일의 내용을 읽고 배열에 저장하기를 원하는 C# 어플리케이션을 만들고 있습니다. 그런 다음 폼의 버튼을 클릭하면 배열에 액세스하기 위해 버튼 클릭 이벤트를 원합니다. 버튼 클릭 이벤트에 배열을 전달하는 방법은 무엇입니까? 아래의 코드에서 "statusArray가 현재 컨텍스트에 존재하지 않습니다"라는 오류가 발생하며 버튼 클릭 이벤트에서 배열에 대한 참조와 관련이 있습니다. 내가 무엇을해야 하나? 양식에 멤버 변수로폼이 read txt 파일을 배열
수잔
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();
}
이 항목도 비공개로 설정하는 것이 좋습니다. –