Valerie Meunier

Valerie Meunier

  • 1.7k
  • 398
  • 16.2k

embedded statement cannot be a declaration ..."

Jan 16 2022 3:36 PM

Hi

I have 6 labels on the form (from toolbox). Now i'm trying to catch them., but this code gives "embedded statement cannot be a declaration ..."

Thanks.

  private void button1_Click(object sender, EventArgs e)
        {
            for (int k = 1; k <= 6; k++)
                Label lbl = (Label)Controls["label" + k.ToString()]; // error
        }


Answers (3)