这是真正的功能吗?叫它

时间:2011-08-25 05:25:38

标签: winforms

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);
}

2 个答案:

答案 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);
}