C#初次建構子練習constructor

第一次練習建構子運用,還需多多練習。
預想是未來可以拉出輸入介面,在傳遞資料給建構子時候逐個欄位中抓入資料,最後再由指令輸出。

主程式:
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            MessageBox.Show("以下為測試資料","溫馨提示");
            student a = new student("Wes", "F123067888", 1999, 12, 25, "0912-456-123");
            student b = new student("Maggie", "F2236088999", 2000, 7, 5, "0912-456-321");
            MessageBox.Show(a.check(),"男");
            MessageBox.Show(b.check(),"女");
        }
    }



物件程式:
class student
    {
        public student(string Name,string ID,int YY,int MM,int DD,string TEL)
        {
            name = Name;
            id = ID;
            yy = YY;
            mm = MM;
            dd = DD;
            tel = TEL;
        }
       
        public int yy, mm, dd;
        public string name, tel , id;

        public string check()
        {
            return "Name : " + name + "\r\nID Number : " + id +
                "\r\nborned : " + yy + "/" + mm + "-" + dd + "\r\nTel : " + tel;
        }
    }

留言