private void calcu(double a,int x)
{
a=Convert.ToDouble(textBox1.Text);
textBox1.Clear();
}
private void button26_Click(object sender, EventArgs e)
{
calcu(a,1);
}
答案 0 :(得分:2)
您是否尝试使用a
方法中的button26_Click
方法分配变量calcu
?
如果是这样,您需要稍微更改一下代码:
private void calcu(out double a, int x)
{
a = Convert.ToDouble(textBox1.Text);
textBox1.Clear();
}
private void button26_Click(object sender, EventArgs e)
{
double a;
calcu(out a, 1);
// Do something with `a`
}
更好的是,为什么不把它变成一个功能?
private double calcu(int x)
{
var a = Convert.ToDouble(textBox1.Text);
textBox1.Clear();
return a;
}
private void button26_Click(object sender, EventArgs e)
{
double a = calcu(1);
// Do something with `a`
}
答案 1 :(得分:0)
private void calcu(double a,int x)
{
a=Convert.ToDouble(textBox1.Text);
textBox1.Text = "";
}
private void button26_Click(object sender, EventArgs e)
{
calcu(a,1);
}