zoukankan      html  css  js  c++  java
  • 类的构造函数 this 关键字

    今天研究了一下mvc 的绑定脚本,绑定样式类。

    看了下源码,里面有一个 构造函数里面 有一个 this 关键字。我想,怎么我的项目没有用到呢。

     

    于是做了一个例子示范了一下。

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace ConsoleApplication1
    {
        class Program
        {
            static void Main(string[] args)
            {
                Bundle b = new Bundle("1", "2");
            }
        }
        public class Bundle
        {
            protected Bundle()
            {
    
            }
    
            public Bundle(string virtualPath, string cdnPath)
                : this(virtualPath, cdnPath, null)
            {
                Console.Write(12);
            }
    
    
            public Bundle(string virtualPath, string cdnPath, object obj)
            {
                Console.Write(123);
            }
        }
    }

    this 关键字出现在这个位置,含义是 继承。

    跟这断点走一遍就会发现,带有2个参数的构造函数,因为继承了带有3个参数的构造函数,因此他会先执行 带有3个参数的构造函数,根据继承的原理,确实是父级先执行。

  • 相关阅读:
    PAT 1036 Boys vs Girls (25分) 比大小而已
    idea创建maven项目慢的原因以及解决方案
    git diff 理解
    git status 命令详解
    java注解
    单例模式
    io分类
    数据库设计的范式
    mysql约束
    mysql去重复关键字distinct的用法
  • 原文地址:https://www.cnblogs.com/bingguang/p/4551127.html
Copyright © 2011-2022 走看看