error with string list in C#

Posted by Chelsea_cole on Stack Overflow See other posts from Stack Overflow or by Chelsea_cole
Published on 2010-04-24T00:48:27Z Indexed on 2010/04/24 1:13 UTC
Read the original article Hit count: 264

Filed under:
|

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!

© Stack Overflow or respective owner

Related posts about c#

Related posts about beginner