I have 5 textboxes with 5 labels,named like this:
text1
,text2
,text3
, etc.label1
,label2
,label3
, etc.
What I want to do is to target each of them and apply the same code, without having to write something individually. I was thinking about a loop like this:
for (int i = 1; i <= 5; i++)
{
try
{
tcpCLient.ConnectAsync(text(i).Text, 80);
label(i).Text = "Online";
}
catch (Exception)
{
label(i).Text = "Offline";
}
}
The problem is that Visual Studio won't let me compile as "The name 'text' does not exist in the current context".
Is this the wrong approach? How would you do this?
Thank you very much!