Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Dynamic Variable C# .Net 4 Windows Form

Posted on 2010-11-16
6
Medium Priority
?
423 Views
Last Modified: 2012-05-10
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.
0
Comment
Question by:Ranidae
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 12

Expert Comment

by:jagssidurala
ID: 34151952
I think you are using this for loop.....the below code satisfies your needs

"myVar" + i = "thatVar" + j
0
 
LVL 2

Author Comment

by:Ranidae
ID: 34151993
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
 
LVL 12

Expert Comment

by:jagssidurala
ID: 34152041
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Author Comment

by:Ranidae
ID: 34152075
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
 
LVL 12

Accepted Solution

by:
jagssidurala earned 1000 total points
ID: 34152211
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
 
LVL 2

Author Comment

by:Ranidae
ID: 34152223
k.. thanks... unfortunate that this is not available in C#.... almost makes me miss VBScript and PHP... almost...
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question