//抽象化(Abstraction) :目的是用有意義的名稱取代無義意的文字。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace Abstraction_ex
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btn_Show_Click(object sender, EventArgs e)
{
CarProfile CP;
CP.Name = "";
CP.Company = "";
string carType = "";
string Msg = "";
switch (combo_CarsType.SelectedIndex)
{
case (int) CarsType.SportsCar:
carType = "跑車";
CP.Name = "Eclipse 2006 GT";
CP.Company = "MITSUBISHI";
break;
case (int) CarsType.Convertibles:
carType = "敞篷車";
CP.Name = "MX-5";
CP.Company = "Mazda";
break;
case (int) CarsType.RV:
carType = "休旅車";
CP.Name = "Tucson";
CP.Company = "Hyundai";
break;
default:
break;
}
Msg = Msg + "車名=" + CP.Name + "/r/n";
Msg = Msg + "公司=" + CP.Company + "/r/n";
Msg = Msg + "汽車類型=" + carType ;
MessageBox.Show(this, Msg, "汽車資訊");
}
}
public struct CarProfile
{
public string Name;
public string Company;
}
public enum CarsType:int
{
SportsCar = 0 ,
Convertibles = 1 ,
RV = 2
}
}