I am trying to create a list of clients. When a user inserts a name of a new client, this name must be added to the list and be shown in a Messagebox. The pre-configured clients are Jack, Sandra, Anna, Tom and Bob. When I run the following script and enter a new client name, a pop-up comes up without the new name. Why is this?
private void btnAddClient_Click(object sender, EventArgs e)
{
string msg = "";
List<string> Clients = new List<string>();
Clients.Add("Jack");
Clients.Add("Sandra");
Clients.Add("Anna");
Clients.Add("Tom");
Clients.Add("Bob");
foreach (string val in Clients)
{
msg += "- " + val + "\n";
}
if (txtAddClient.Text == "")
{
MessageBox.Show("No client name has been entered!");
}
else
{
string newClient = txtAddClient.Text;
Clients.Add(newClient);
MessageBox.Show(msg);
}
}
UPDATED: