You are on the right track - to an extent.
But...I'd build the list when I did the validation each time (otherwise you could include "old" strings in current tests if the user goes back and changes them.)
Multiple textboxes containing just "!" is allowed - so check that when you add them to your list:
List<string> boxes = new List<string>();
foreach (Control c in Controls)
{
Textbox tb = c as TextBox;
if (tb != null)
{
if (tb.Text != "!") boxes.Add(tb.Text);
}
}
Then, sort the list:
boxes.Sort();
Now, if there are any duplicates, they are side-by-side in the list, so a simple loop through checking against the previous list entry will tell you if there are any duplicates:
string last = "!";
foreach (string s in boxes)
{
if (s == last)
{
MessageBox.Show("Duplicate: " + s);
break;
}
last = s;
}