C#之类的使用

属性与字段的使用类似iOS

    class Class1 {
        //字段私有,属性公有
        private string _name;
        private int _age;
/*control + r -> e 快速创建属性*/
public string Name { set { _name = value; } get { return _name; } } public int Age { set { _age = value; } get { return _age; } }
        //构造函数
        public Class1(string name, int age) {
            this.Name = name;
            this.Age = age;
        }
public void Function() { Console.WriteLine("姓名{0},年龄{1}",this.Name,this.Age); }

        //析构函数
        ~Class1(){


        }

   Text text = new Text() { age = 23 };//对象初始化器

    }

 基类的虚方法(virtual)可以实现继承重写(override)进而实现多态;

 抽象类(abstract)的抽象方法(无方法体)也可以实现继承重写(override)实现多态;

posted @ 2016-09-28 23:34  刘冠  阅读(222)  评论(0编辑  收藏  举报