构造函数和:this()的应用

一、构造函数和:this()的应用

//本实例演示构造函数和:this()的应用
public class ClsA
{
    public string A{set;get;}
    public string B { set; get; }
}
//定义一种释放分配的资源的方法。
class ClsB
{
    //定义构造函数
    public ClsB(string x, string y) { }

    //重载构造函数,并给现有的构造函数赋值
    public ClsB(ClsA cls) : this(cls.A, cls.B)
    {
    }
}

 

posted @ 2016-04-12 21:53  microsoftzhcn  阅读(791)  评论(0编辑  收藏  举报