练习(实例函数)

    public class MAN
    {
        public string Xingming{ get; set; }

        public string Xingbie { get; set; }

        private string shengao;//私有变量

        public string Shengao //封装
        {
            get { return shengao; }
            set
            {
                if (!string.IsNullOrWhiteSpace(value))//判段条件
                { shengao = value; }
            }
        }

        public string Tizhong //封装
        {
            get;
            set;
        }
        //重构
        public MAN(){}
        public MAN(string shengao,string tizhong)
        {
            this.Tizhong = tizhong;
            this.shengao = shengao;
        }
    }
 class Program
    {
        static void Main(string[] args)
        {
            MAN man = new MAN("180cm","80kg");

            man.Xingming = "张三";
            man.Xingbie = "";
            //man.Shengao = "170cm";
           //man.Tizhong = "70kg";

            Console.WriteLine("这个人的信息:姓名:"+man.Xingming+" 性别:"+man.Xingbie+" 身高:"+man.Shengao+" 体重:"+man.Tizhong);

            Console.ReadLine();
        }
    }

 

posted @ 2015-09-23 20:46  大魔王·牛头  阅读(199)  评论(0编辑  收藏  举报