W
W
wolfak2015-05-25 21:07:36
WPF
wolfak, 2015-05-25 21:07:36

How to set the values ​​of 15 variables in c#, the names of which change by one?

Good time of the day.
There are 15 variables:
per1
per2
per3
...
per15
How can I set them to different values ​​using a loop? Actually, the question is how to set the iteration value in the name of the variable "per" + i?
if not variables, then values ​​from XAML, x:Name. On PHP or Javascript coped with this task.
I will be very grateful for your help.
Visual Studio IDE, C#

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
dordzhiev, 2015-05-25
@wolfak

Then XAML elements, not variables. Something is wrong anyway, have you tried the ListView?
On the subject: use the FindName() method. It will be something like this:

for (int i = 1; i <= 15; i++)
{
  var element = (UIElement) FindName("per" + i);
  // ...
}

B
bobrovskyserg, 2015-05-25
@bobrovskyserg

Generally for such cases indexed variables - arrays are thought up.
But if you want to be perverted - write it down with your hands, 15 variables - not God knows what kind of work.

S
Spetros, 2015-05-25
@Spetros

Have you tried arrays?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question