0

I'd like to loop through my controls and make an IF conditional, but instead using this:

foreach(Control c in this.Controls)
    {
      if(c is TextBox) {}
    }

I'd like to do something like:

if(!c is TextBox){}

you know ? I'd like to get into the loop only if the control C is DIFFERENT of a TextBox. Of course the method I tried ! does not work with Controls. How may I deny that ?

PlayHardGoPro
  • 2,791
  • 10
  • 51
  • 90

2 Answers2

6

Just include condition into parenthesis:

if (!(c is TextBox)) {}
Andrei
  • 55,890
  • 9
  • 87
  • 108
2
foreach(Control c in this.Controls)
{
   if(!(c is TextBox))
   {
      //do something
   }
}
Yami
  • 1,405
  • 1
  • 11
  • 16