我已经确定了这个错误,我尝试了如何解决它,但无效。
我有这段代码:
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
。我怎么能这样做呢?
答案 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));
}