- 最後登錄
- 2022-5-1
- 在線時間
- 2 小時
- 註冊時間
- 2009-8-27
- 閱讀權限
- 20
- 精華
- 0
- UID
- 6950159
- 帖子
- 33
- 積分
- 23 點
- 潛水值
- 3604 米
| 如果發覺自己無法使用一些功能或出現問題,請按重新整理一次,並待所有網頁內容完全載入後5秒才進行操作。 我是一位菜鳥,想學C#
這個範例是我參考某教科書所看到的實作範例
此題實在寫不出來,想請教高手如何解題??麻煩了
Q. 題目是新增投票後,歌手名單與投票結果清單項目,會依照票數排序??
我隨教科書指導實作到以下程式,
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace WindowsFormsApplication12
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- string[] singer = new string[] { "林宥嘉", "周杰倫", "蕭敬騰", "小宇", "方大同" };
- string[] msg = new string[] { "大小說家/華研", "12新作/杰威爾", "以愛之名/華納", "在一次/愛貝克思", "回到未來/華納" };
- int [] votes = new int [5];
- private void Form1_Load(object sender, EventArgs e)
- {
-
- cbosinger.Items.AddRange(singer);
- for (int i = 0; i < singer.Length; i++) {
- lstVote.Items.Add(singer[i] + "\t" + votes[i] + "票");
- }
- cbosinger.SelectedItem = singer[0];
- }
- private void cbosinger_SelectedIndexChanged(object sender, EventArgs e)
- {
- lblMsg.Text = msg[cbosinger.SelectedIndex];
- }
- private void btnVote_Click(object sender, EventArgs e)
- {
- votes[cbosinger.SelectedIndex] += 1;
- lstVote.Items.Clear();
- for (int i = 0; i < votes.Length; i++)
- {
- lstVote.Items.Add(singer[i] + "\t" + votes[i] + "票");
- }
- }
- }
- }
複製代碼
... |
附件: 你需要登錄才可以下載或查看附件。沒有帳號?註冊 |