error with string list in C#
- by Chelsea_cole
Same namespace: 2 forms.
public class Account //frm1
{
public string Username;
public string Password;
}
public class ListAcc
{
public static List<Account> UserList;
}
private void button1_Click(object sender, EventArgs e)
{
List<Account> UserList = new List<Account>();
Account acc = new Account();
acc.Username = textBox1.Text;
acc.Password = textBox2.Text;
UserList.Add(acc);
}
private void button2_Click(object sender, EventArgs e) //frm2
{
string p = frmDangky.ListAcc.UserList[0].Username; // null ->error
string p = frmDangky.ListAcc.UserList[0].Password; // null ->error
}
Someone help me? :( why my string is NULL???????? The textBox is not empty... Thanks!