Example #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            MyRectangle item = (MyRectangle)comboBox1.SelectedItem;

            //(MyRectangle)轉型用的 被選到項目(return object)
            //將被選到的項目(object)轉型成MyRectangle型態 存到 item
            MessageBox.Show($"{item.Name} 的面積為{item.GetArea()}");
        }
        private void button1_Click(object sender, EventArgs e)
        {
            MyRectangle item = (MyRectangle)comboBox1.SelectedItem;

            MessageBox.Show($" {item.Name} 的面積為: {item.GetArea()}");
        }