Dynamic Variable C# .Net 4 Windows Form

Hello Experts,

I need to set variables dynamically in a C# windows Form application.  I've done this before in VBScript using "Execute":

Execute("myVar" & i & "=thatVar" & j)

in PHP:

${"myVar".i} = ${"thatVar".j};

Now... how can I do that in C#?

Thanks in advance.
LVL 2
RanidaeAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
jagssiduralaConnect With a Mentor Commented:
you can not get variable name by concatnating the static text and with some number(in your case).

for this you have to write if condition for every variable.

we can write loop for a collection and not for the same type(naming convention like btest1,btest2...) of individual variables.
0
 
jagssiduralaCommented:
I think you are using this for loop.....the below code satisfies your needs

"myVar" + i = "thatVar" + j
0
 
RanidaeAuthor Commented:
That doesn't work in c#, or if it does, I can't figure it out.
The goal is:

Boolean bTest1 = true;
Boolean bTest2 = false;
Boolean bTest3 = true;

for(int i =1; i<=3 ;i++)
{
   if(bTest + i} { dosomething(); }
}

0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
jagssiduralaCommented:
As per your above code you are executing same code if any of the boolean variable value to true, so what is need of 3 variables.you can use one boolean variable.

 if you execute different code for every variable you need write if condition for every variable.
0
 
RanidaeAuthor Commented:
The three shown are only for demo.

The true code is looking to do:

for(int i = 1; i <=15; i++)
{
     if(properties.settings.Default.extensionAttribute+i)
    {
         dostuff();
    }
}
0
 
RanidaeAuthor Commented:
k.. thanks... unfortunate that this is not available in C#.... almost makes me miss VBScript and PHP... almost...
0
All Courses

From novice to tech pro — start learning today.