'How to use the same var on different events

I want to use double test in the second event how can I do it? I don't want to define double test again in the second event I want to use reference.

public sealed partial class MainPage : Page
    {
        public MainPage()
        {
            this.InitializeComponent();
        }

        public void Button_Click(object sender, RoutedEventArgs e)
        {
            double test = double.Parse(txt.Text);
            test // I want to use this var in the event below how
        }

        public void Button_Click_1(object sender, RoutedEventArgs e)
        {
            test // doesn't recognaize double test in the first event
        }
    }


Solution 1:[1]

you can do this if you create a member variable like this:

public sealed partial class MainPage : Page
{
    public MainPage()
    {
        this.InitializeComponent();
    }
    double test = 0;
    public void Button_Click(object sender, RoutedEventArgs e)
    {
        test  = double.Parse(txt.Text);
        //test // I want to use this var in the event below how
    }

    public void Button_Click_1(object sender, RoutedEventArgs e)
    {
        MessageBox.Show(test.ToString());
        //test // doesn't recognaize double test in the first event
    }
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1