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

posted @ 2015-06-04 10:36  pengbg  阅读(306)  评论(0编辑  收藏  举报