zoukankan      html  css  js  c++  java
  • new关键字 、this关键字、base关键字

    使用new,所做的三件事:

    1. (类是引用对象,引用对象是在堆中开辟空间)在堆中开辟空间

    2. 在开辟的堆空间中创建对象

    3. 调用对象的构建函数

    4. 隐藏父类成员:子类的成员可以与隐藏从父类继承的成员,类似于重写。public new void SayHello()

     this关键字的使用

    1. 代表当前类的对象

    2. 显示的调用自己的构造函数

            public BaseFile(string filePath,string fileName,string time)
            {
                this.FileName = fileName;
                this.FilePath = filePath;
                this.Time = _time;
            }
    
            /*
             public BaseFile(string filePath,string fileName)
            {
                this.FileName = fileName;
                this.FilePath = filePath;
            }
             */
            //可替换下面的定义:这样减少了代码冗余。用法同public BaseFile(string filePath,string fileName)一样
            public BaseFile(string filePath,string fileName):this(filePath,fileName,null)
            { }
    

    base关键字的使用

    1. 显示调用父类的构造函数

    2. 调用父类的成员

  • 相关阅读:
    正则表达式(验证账号密码邮箱身份证)
    JS Fetch
    事件流动
    JS DOM和BOM
    CSS的定位
    For each...in / For...in / For...of 的解释和例子
    CSS的gridlayout
    CSS position属性
    CSS的颜色
    twelfth week
  • 原文地址:https://www.cnblogs.com/my-cat/p/7601788.html
Copyright © 2011-2022 走看看