Get textboxes in to a list! c#
- by Chelsea_cole
public class Account
{
public string Username
{
get { return Username; }
set { Username = value; }
}
}
public class ListAcc
{
static void Data()
{
List<Account> UserList = new List<Account>();
//example of adding user account
Account acc = new Account();
acc.Username = textBox1.Text; //error
UserList.Add(acc);
}
}
there are a error from access to textBox1.Text? ( An object reference is required for the nonstatic field, method, or property)... Someone can help?
but if the code is:
private void textBox1_TextChanged(object sender, EventArgs e)
{
List<Account> UserList = new List<Account>();
//example of adding user account
Account acc = new Account();
acc.Username = textBox1.Text;
UserList.Add(acc);
}
it's work! someone can help me fix my error? Many thanks!