I've referred to this link (thread 1) but I get an error. For my example, I only have one list in one class. The class name is Savestate. I have 2 forms.
Form1 contain a textbox where the string that I saved inside will be transferred to the list when I press button1. Button1 will also open
Form2 where there is a label that should reflect the string in the textbox. However, the label will reflect systems.collection...
Below is my code.
Savestate: class name
public static List<string> number = new List<string>();
Form1
private void button1_click(object sender, System.EventArgs e)
{
Savestate.number.Add(textbox1.Text);
Formscollection.Form1.Hide(); //Form 1 and Form 2 saved in another class called formscollection
Formscollection.Form2.Show();
}
Form2 (Show the systems.collections..)
private void Form2_VisibleChanged(object sender, EventArgs e)
{
label1.Text = Savestate. number.ToString();
}
I tried another code based on other forums but I received an error
Form2 (got error: cannot implicitly convert type void to string)
private void Form2_VisibleChanged(object sender, EventArgs e)
{
foreach (string item in Savestate.number)
{
label1.Text = Console.WriteLine(item)
}
}
Hope to get help. Thanks.