2015年11月9日 星期一

C8_1 Person.cs 基底類別

using System;
namespace C8_1
{
    ///
    ///抽象基底類別Person
    ///
    public abstract class Person
    {
        private string s_name;
        private int i_age;
        private float f_height;
        private float f_weight;
        private string s_sex;
        ///
        ///自定義建構子 Person
        ///
        ///姓名
        ///年齡
        ///身高
        ///體重
        ///性別
        public Person(string name, int age, float height, float weight, string sex)
        {
            s_name = name;
            i_age = age;
            f_height = height;
            f_weight = weight;
            s_sex = sex;
        }
        ///
        ///預設建構子
        ///
        public Person() { }
        ///
        ///定義屬性
        ///
        public string Name
        {
            get
            {
                return s_name;
            }
            set
            {
                if (s_name != value)
                {
                    s_name = value;
                }
            }
        }
        public int Age
        {
            get
            {
                return i_age;
            }
            set
            {
                if (i_age != value)
                    i_age = value;
            }
        }
        public float Height
        {
            get
            {
                return f_height;
            }
            set
            {
                if (f_height != value)
                    f_height = value;
            }
        }
        public float Weight
        {
            get { return f_weight; }
            set { if (f_weight != value) f_weight = value; }
        }
        public string sex
        {
            get { return s_sex; }
            set { if (s_sex != value) s_sex = value; }
        }
        ///
        ///勞動操作
        ///
        public abstract void DoWork();
        //static void Main(){}
       
    }
}

沒有留言: