错误CS0103名称' peremennaya_slozenie'在当前上下文中不存在

时间:2015-09-22 19:25:14

标签: c# windows windows-10 win-universal-app

我已经确定了这个错误,我尝试了如何解决它,但无效。

我有这段代码:

 public void button_plus_Click(object sender, RoutedEventArgs e)
    {
        int peremennaya_slozenie= Convert.ToInt32(ekran.Text);
    }

    private void button_rvno_Click(object sender, RoutedEventArgs e)
    {
        ekran.Text = Convert.ToString(peremennaya_slozenie + Convert.ToInt32(ekran.Text));
    }

我想在方法peremennaya_slozenie中使用方法button_plus_Click中的button_rvno_Click。我怎么能这样做呢?

1 个答案:

答案 0 :(得分:1)

您应该将peremennaya_slozenie变量的声明移到类级别:

private int peremennaya_slozenie;

public void button_plus_Click(object sender, RoutedEventArgs e)
{
    peremennaya_slozenie = Convert.ToInt32(ekran.Text);
}

private void button_rvno_Click(object sender, RoutedEventArgs e)
{
    ekran.Text = Convert.ToString(peremennaya_slozenie + Convert.ToInt32(ekran.Text));
}