2
Answers

Getting variable in another function

Ask a question
yokzu

yokzu

14y
2.1k
1
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.
        }

Answers (2)