Get textboxes in to a list! c#

Posted by Chelsea_cole on Stack Overflow See other posts from Stack Overflow or by Chelsea_cole
Published on 2010-04-23T07:19:58Z Indexed on 2010/04/23 7:23 UTC
Read the original article Hit count: 154

Filed under:
 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!

© Stack Overflow or respective owner

Related posts about c#