In the below example is it possible to use the kvp.value to point a global variable (num1, num2, num3)?
int num1;
int num2;
int num3;
private void button1_Click(object sender, EventArgs e)
{
List<KeyValuePair<TextBox, string>> myList = new List<KeyValuePair<TextBox, string>>();
myList.Add(new KeyValuePair<TextBox, string>(textBox1, "num1"));
myList.Add(new KeyValuePair<TextBox, string>(textBox2, "num2"));
myList.Add(new KeyValuePair<TextBox, string>(textBox3, "num3"));
foreach (KeyValuePair<TextBox, string> kvp in myList)
{
TextBox tb= kvp.Key;
try
{
num1 = int.Parse(tb.Text);
//instead of using the hardcoded variable name num1 i want to use kvp.value
//kvp.value = int.Parse(tb.Text);
}
catch
{
//blah blah
}
}
}
I deleted my previous post as it was very unclear, hopefully this is a bit better.