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 c6_3 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } string[] name = new string[5]; int[] money = new int[5]; private void Form1_Load(object sender, EventArgs e) { name[0] = "蘋果"; name[1] = "香蕉"; name[2] = "橘子"; name[3] = "葡萄"; name[4] = "西瓜"; foreach(string item in name) { listBox1.Items.Add(item); } money[0] = 50; money[1] = 15; money[2] = 20; money[3] = 70; money[4] = 150; } private void listBox1_SelectedIndexChanged(object sender, EventArgs e) { textBox1.Text = name[listBox1.SelectedIndex]; textBox2.Text = money[listBox1.SelectedIndex].ToString(); } } }