Я написал несколько строк кода в C#, чтобы перебирать список, но я печатаю только в текстовом поле. код, который я написал:цикл через список в C#
//For instantiation
Account account = new Account(0,"","", 0);
//A list for class Account
List<Account> listAccount = new List<Account>();
//Button for adding new Customer
private void button1_Click(object sender, EventArgs e)
{
account.CustomerID = int.Parse(customerIdTxt.Text);
account.CustomerFullName = customerNameTxt.Text;
account.CustomerAddress = customerAddrTxt.Text;
listAccount.Add(account);
}
//For printing the Customer's detailes in textbox
private void button6_Click(object sender, EventArgs e)
{
string showCustDetailes = "";
for(int i=0;i<listAccount.Count;i++)
{
showCustDetailes+=
"Customer ID : " + listAccount[i].CustomerID + Environment.NewLine +
"Customer Name : " + listAccount[i].CustomerFullName + Environment.NewLine +
"Customer Address : " + listAccount[i].CustomerAddress + Environment.NewLine +
"---------------------------------------------------" + Environment.NewLine;
}
viewDetailesTxt.Text = showCustDetailes;
}
кто может помочь мне, как я могу напечатать все клиент список
Когда вы говорите, «Последний один» вы имеете в виду только линию «Customer Address», или вы имеете в виду только один полный идентификатор, имя и адресная строка? – CathalMF
Также убедитесь, что ваш TextBox является многострочным текстовым полем, иначе он будет поддерживать только одну строку. –
Вы используете только один экземпляр 'Account'. – cubrr