0

I am newbie in C# and I have a question.

I have that objects:

PictureBox field1;
PictureBox field2;
PictureBox field3;

And the question:

Is this possible to get that objects "dynamically" using its names?

I mean something like that:

for(int i = 0; i < 3; i++) {
     // instead of that:
     string tmp1 = field1.Name;
     string tmp2 = field2.Name;
     string tmp3 = field3.Name;
  
     // i need something like that:
     string tmp = "and this is a string parameter".Name;
} 
Brarord
  • 611
  • 5
  • 18
  • 1
    Is [this](https://stackoverflow.com/q/1536739/8967612) what you're trying to do? – 41686d6564 stands w. Palestine Jul 08 '20 at 22:06
  • 1
    Ahmed Abdelhammed and Olivier Rogier yes that was my solve, thanks you so much guys! – Brarord Jul 08 '20 at 22:11
  • 1
    You can also use for example `this.Controls.OfType().Where(c => c.Name.StartWith("Something");`. Also: https://stackoverflow.com/questions/62791731/mouseover-controls-and-display-its-handle/62792703#62792703 for the idea of recurse search controls (panels on the form that contains controls and panels and so on). –  Jul 08 '20 at 22:12

0 Answers0