[C#] ตัวแปร Enumeration

โค้ด
namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        public enum vs : int
        {
            vs5     = 5,
            vs6     = 6,
            vsnet   = 7,
            vs2005  = 8
        }

        public enum ofc : int
        {
            ofc95   = 5,
            ofc97   = 6,
            ofc2000 = 7,
            ofcxp   = 8,
            ofc2003 = 11,
            ofc2007 = 12
        }

        private void buttonSummary_Click(object sender, EventArgs e)
        {
            if ((listBox1.SelectedIndex == -1) || (listBox2.SelectedIndex == -1))
            {
                MessageBox.Show("คุณยังไม่ได้เลือกเวอร์ชันซอฟต์แวร์", "ผิดพลาดครับ");
            }
            else
            {
                string strOut = "";
                
                int a = 0;
                string choice1 = listBox1.SelectedItem.ToString();
                switch (choice1)
                {
                    case "Visual Studio 5":
                        a = (int)vs.vs5;
                        break;
                    case "Visual Studio 6":
                        a = (int)vs.vs6;
                        break;
                    case "Visual Studio .NET":
                        a = (int)vs.vsnet;
                        break;
                    case "Visual Studio 2005":
                        a = (int)vs.vs2005;
                        break;
                }
                strOut += choice1 + " ตรงกับเวอร์ชัน " + a.ToString();


                int b = 0;
                string choice2 = listBox2.SelectedItem.ToString();
                switch (choice2)
                {
                    case "Office 95":
                        b = (int)ofc.ofc95;
                        break;
                    case "Office 97":
                        b = (int)ofc.ofc97;
                        break;
                    case "Office 2000":
                        b = (int)ofc.ofc2000;
                        break;
                    case "Office XP":
                        b = (int)ofc.ofcxp;
                        break;
                    case "Office 2003":
                        b = (int)ofc.ofc2003;
                        break;
                    case "Office 2007":
                        b = (int)ofc.ofc2007;
                        break;
                }
                strOut += "\n";
                strOut += choice2 + " ตรงกับเวอร์ชัน " + b.ToString();
                MessageBox.Show(strOut);
            }
        }
    }
}
Previous
Next Post »