Hi.
I want to get var1 variable in button1_Click function but its getting null in there. How can I do that?
public string var1;
public void func()
{
while (true)
{
...
string var1 = "this is example";
}
private void button1_Click(object sender, EventArgs e)
{
label2.Text = var1; // -----> var1's value is null in here.
}
Getting variable in another function
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.

theLizardRank #1,079 · 1.8K reputationPosted Dec 27, 2009, 2:21 PM EST
The one in the function exists ONLY in the function that is why you are getting null outside of the function.
do one or the other.
var1 = "this example";
or
public string func() return(var1);
yokzuRank #5,421 · 300 reputationPosted Dec 27, 2009, 2:38 PM EST