C#关键字base

例子:

        public CustomStroke(SharpType type)
            :base()
        {
            this.type = type;
       
        }

这里的CustomStroke继承与基类Stroke类,用关键字base调用了基类stroke类中的构造方法。


如果基类没有提供默认构造函数,派生类必须使用 base 显式调用基构造函数。

构造函数可以使用 this 关键字调用同一对象中的另一构造函数。和 base 一样,this 可带参数使用也可不带参数使用,构造函数中的任何参数都可用作 this 的参数,或者用作表达式的一部分。例如,可以使用 this 重写构造函数:

 1 public Manager(int initialdata)
 2     : base()
 3 {
 4     //Add further instructions here.
 5 }
 6 
 7 public Employee(int weeklySalary, int numberOfWeeks)
 8     : this(weeklySalary * numberOfWeeks)
 9 {
10 }


 

posted @ 2016-01-21 16:12  SeeKHit  阅读(338)  评论(0编辑  收藏  举报