Skip to content

Quick Question - Newbie

Antonio

Asked Sep 28, 2005, 10:05 AM EDT1 answer
Share
LinkedInX
Ok assume the following: public Form1() { InitializeComponent(); string b = "Hello"; } public void button1_Click(object sender, System.EventArgs e) { label1.Text = b; } If they're both in the namespace how come I can't refer to b in the button click event handling code? I know I can declare the string b in that specific part locally but the whole idea is to figure out why my button handling code can't use anything outside of it. Help please. Thanks.

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • 0

    Would moving your string declaration to a "Class" level variable do what you want?

    ------------------------
    private string b = "Hello";

    public Form1()
    {
     InitializeComponent();
     b = "Hello";
    }

    public void button1_Click(object sender, System.EventArgs e)
    {
     label1.Text = b;
    }
    --------------------------

    0