I want to display data in listbox , but I can not use listBox1 in function , I declare it in program but can not use in function , how can I use listBox1 in function to display data
void threetask(ref Int32 x,ref Int32 y)
{
//do something
listBox1.Items.Add(x);//error
listBox1.Items.Add(y);//error
}
private void button2_Click(object sender, EventArgs e)
{
ListBox listBox1 = new ListBox();
this.Controls.Add(listBox1);
threetask(ref x,ref y);
}
Copyright Notice:Content Author:「user3226824」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/21966656/error-when-use-listbox-to-display-data-in-function