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);
}
}
訪問textBox1.Text時出現錯誤? (非靜態字段,方法或屬性需要對象引用...有人可以提供幫助嗎?將文本框添加到列表中! c#
但如果代碼是:
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);
}
它的工作!有人可以幫助我解決我的錯誤?非常感謝!
是的,我認爲是的!那麼,在所有文本框中獲取完整字符串的最佳方法是什麼? – 2010-04-23 07:40:13
使用按鈕並處理該按鈕的單擊事件以獲取每個TextBox中的文本並調用Data方法。 For循環將很好地工作。 – anonymous 2010-04-23 07:53:20