I have a following program, it takes strings from 4 textboxes and puts them into array and displays the message(created from the array) after user clicks on btnOK. I have a button called btnClear which if clicked should clear both the message string and array but it's not doing it and I'm not quite sure why, can someone have a look and advise.
string[,] namesTable = new string[10, 4];
int row = 0;
string message = "";
private void btnOK_Click_1(object sender, EventArgs e)
{
namesTable[row, 0] = txtFirstName.Text;
namesTable[row, 1] = txtSurname.Text;
namesTable[row, 2] = txtPosition.Text;
namesTable[row, 3] = txtComment.Text;
row++;
message = "Name.\tSurname\tPosition\tComment\n";
for (int i = 0; i < namesTable.GetLength(0); i++)
{
if (namesTable[i, 0] != null)
{
for (int j = 0; j < namesTable.GetLength(1); j++)
{
message += namesTable[i, j] + "\t";
}
message += "\n";
}
}
MessageBox.Show(message, "Names Table");
}
private void btnClear_Click_1(object sender, EventArgs e)
{
Array.Clear(namesTable, 0, 4);
message = "";
}
If you need more info please let me know.