2011-08-25 41 views
-2
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); 
} 
+1

究竟什麼是您所遇到的問題? – griegs

+0

我第二@griegs,有什麼問題? –

回答

2

你們是不是要分配變量abutton26_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` 
} 
+0

+1,我更喜歡你的。再加上我認爲你只是在我之前的幾秒鐘 – griegs

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); 
} 
相關問題