• 类的初始化器(调用其父类构造函数、调用自己其他构造函数)


    namespace ClassLib
    {
        public class ClassBase
        {
            //无参数的构造函数
            public ClassBase(){
            }
            public string property { set; get; }
            //带参数的构造函数
            public ClassBase(string a){
                this.property = a;
            }
        }
    }
    

      

    namespace ClassLib
    {
        public class ClassChild:ClassBase
        {
            //调用其父类构造函数
            public ClassChild()
                : base(){
    
            }
            //调用其父类带参数的构造函数
            public ClassChild(string b)
                : base(b){
    
            }
        }
    }
    

      

    namespace ClassLib
    {
        public class ClassThis
        {
            //this用法,this指当前实例对象的指针 this = new Object();Object为任意对象
            private string getList(string str)
            {
                return string.Format("字符:{0}", str);
            }
            public string getString(string str)
            {
                return this.getList(str);  //等同于new ClassThis.getList(str);
            }
    
            public string thisParent { get; set; }
            //定义构造函数
            public ClassThis(){
                this.thisParent= "thisParent";
            }
            public string thisChild { get; set; }
            //调用自己的构造函数
            public ClassThis(string child)
                : this(){
                thisChild = child;
            }
          }
    }
    

      

  • 相关阅读:
    移动端判断键盘弹出和收起
    【JS】空格分隔手机号
    【vue】中 provide 和 inject 的使用方法
    【vue】中 $parent 和 $children 的使用方法
    第一个COCOS2d项目
    C语言性能优化与基础知识
    OC中的protocol
    OC中的block数据类型
    OC的ARC机制
    OC内存管理
  • 原文地址:https://www.cnblogs.com/sntetwt/p/3500844.html
Copyright © 2020-2023  润新知