- 最後登錄
- 2023-4-12
- 在線時間
- 1 小時
- 註冊時間
- 2007-6-9
- 閱讀權限
- 20
- 精華
- 0
- UID
- 1508193
- 帖子
- 434
- 積分
- 325 點
- 潛水值
- 16002 米
| 本帖最後由 vihee 於 2016-3-5 09:05 PM 編輯
- List<double> listScore = new List<double>();
- private void button1_Click(object sender, EventArgs e)
- {
-
- string name = textBox1.Text;
- string chinese = textBox2.Text;
- string english = textBox3.Text;
- string mathematics = textBox4.Text;
- listScore.Clear();
- getScoreToList(chinese);
- getScoreToList(english);
- getScoreToList(mathematics);
- textBox5.Text = String.Format("{0}各科成績如下:{1}國文:{2}{1}英文:{3}{1}數學:{4}{1}平均成績:{5}", name, Environment.NewLine, chinese, english, mathematics, listScore.Average());
- }
- private void getScoreToList(string chinese)
- {
- double doubleScore = getDoubleScore(chinese);
- if (doubleScore != -1)
- {
- listScore.Add(doubleScore);
- }
- }
- private double getDoubleScore(string sScore)
- {
- double dScore = -1;
- if (double.TryParse(sScore, out dScore))
- { }
- return dScore;
- }
複製代碼
... |
|