Re: [問題] 副程式裡面呼叫需要傳回值的副程式
: 可是我現在在我的button按鈕下編寫下列程式碼
: private void button1_Click(object sender, System.EventArgs e)
: {
: string g1,h1;
妳將g1, h1宣告為function scope的區域變數(意思就是,只有在這個function中看的到)
這邊就是問題所在
: double ans=0;
: h1 = textBox1.Text;
: g1 = textBox5.Text;
: CalculateGPA();
: textBox10.Text = ans.ToString();
: }
: static void CalculateGPA()
: {
: int p=0,h=0;
: p = MapToPoint(g1);
: h = MapToIntHours(h1);
這邊直接叫用g1, h1自然就會看不到了
解決辦法是讓CalculateGPA這個sub設定兩個參數來傳值
or
將h1, g1宣告在函式以外的地方,這樣就成了class scope(有點類似C的全域變數)
: }
: 編譯的時候卻跟我說
: The name 'g1' does not exist in the class or namespace 'GPA.Form1'
: The name 'h1' does not exist in the class or namespace 'GPA.Form1'
: 怎麼會這樣呢?
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 203.73.237.254
推
09/25 00:17, , 1F
09/25 00:17, 1F
推
09/25 07:34, , 2F
09/25 07:34, 2F
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 4 之 4 篇):
C_Sharp 近期熱門文章
PTT數位生活區 即時熱門文章