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个参数的构造函数,根据继承的原理,确实是父级先执行。

  • 相关阅读:
    cf-779E (拆位)
    石子游戏 (SG函数)
    [POI2017] Flappy Bird (思维题)
    Alice and Bob (SG函数)
    Red is good (DP)
    CodeVS-1669 (背包问题)
    GalaxyOJ-468 (LCA)
    BZOJ-1191 (二分图匹配)
    Reinforcement Learning 笔记(4)
    Reinforcement Learning 笔记(3)
  • 原文地址:https://www.cnblogs.com/bingguang/p/4551127.html
Copyright © 2011-2022 走看看