码迷,mamicode.com
首页 > Windows程序 > 详细

c#构造函数

时间:2015-03-02 11:05:12      阅读:176      评论:0      收藏:0      [点我收藏+]

标签:

子类调用父类的构造函数通过符号:

如果基类中定义了带参数的一个或者多个构造函数,则派生类中也必须定义至少一个构造函数,且派生类中的构造函数都必须通过base()函数“调用”基类中的某一个构造函数。

public class fatherBase
  {
    public string Name{get;set;}
    public int Age{get;set;}
    public int Id{get;set;}
    public fatherBase()
    {}
    public fatherBase(string name,string age,string id){
    this.Name=name;
    this.Age=age;
    this.Id=id;
    }
  }

public class baby:fatherBase
 {
   public string Test{get;set;}
   public baby()
   {}
   public baby(string test,string name,string age,string id):
    base(name,age,id)
    {
    this.Test=test;
    }
  }

c#构造函数

标签:

原文地址:http://www.cnblogs.com/ilooking/p/4308072.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!