So I posted the same question but with calling a label with a variable
(http://www.c-sharpcorner.com/Forums/Thread/246996/)
Now I need to call a variable with a variable.
I've tried to modify the code given in the before mentioned thread, but with no luck.
So my question, can it be done? And if so, how?
Saying I have a variable called Cookie, I need to call the variable that equals what is written in the Cookie variable.
Say, Cookie = "Cake"; I would wanna call the Cake variable.
As mentioned I've tried modifying the code given to the label question (thread as mentioned before), but it didn't work. Here's the code I tried:
String TheLabel = (String)this.Controls[cookie];
Please help, I will love you forever if you do :)
Loading
VulpesPosted Feb 27, 2014, 7:22 AM
To write to a variable, you'd then need to assign a new string to it (as you normally would) and then refresh the dictionary value as well:
Michael MortensenPosted Feb 27, 2014, 6:54 AM
Why do I need the drink?
Why do I need to chnge Cookie twice?
and how do I write to the variable?
VulpesPosted Feb 27, 2014, 6:36 AM
If they're local variables, you'd need to build some sort of dictionary. For example:
A similar approach would also work for class-level variables (or fields) though you could also use reflection as well.
using System;