Skip to content

Instantly share code, notes, and snippets.

@edward-hsu-1994
Created April 15, 2015 14:50
Show Gist options
  • Save edward-hsu-1994/83f3036f2f31d8a0270e to your computer and use it in GitHub Desktop.
Save edward-hsu-1994/83f3036f2f31d8a0270e to your computer and use it in GitHub Desktop.
for eyny sample
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 EynyTest_20150415 {
public partial class Form1 : Form {
public class Singer {
public string Name { get; set; }
public string Album { get; set; }
public int Votes { get; set; }
public override string ToString() {
return string.Format("{0}\t{1}",Name,Votes);
}
}
public Form1() {
InitializeComponent();
}
Singer[] SingerList;
private void Form1_Load(object sender ,EventArgs e) {
SingerList = new Singer[]{//寫入初始的清單
new Singer(){ Name = "林祐嘉",Album = "大小說家/華研"},
new Singer(){ Name = "周杰倫",Album = "12新作/傑威爾"},
new Singer(){ Name = "蕭敬騰",Album = "以愛之名/華納"},
new Singer(){ Name = "小宇" ,Album="在一次/愛貝克斯"},
new Singer(){ Name = "方大同",Album = "回到未來/華納"}
};
foreach(Singer singer in SingerList) {
comboBox1.Items.Add(singer.Name);
}
DisplayList();
}
private void comboBox1_SelectedIndexChanged(object sender ,EventArgs e) {
if(comboBox1.SelectedIndex == -1)return;
label1.Text = SingerList[comboBox1.SelectedIndex].Album;
}
private void button1_Click(object sender ,EventArgs e) {
if(comboBox1.SelectedIndex == -1)return;
SingerList[comboBox1.SelectedIndex].Votes++;
DisplayList();
}
private void DisplayList() {
var OrderList = from t in SingerList
orderby t.Votes descending
select t;
listBox1.Items.Clear();
foreach(var Item in OrderList) {
listBox1.Items.Add(Item.ToString());
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment