快上网专注成都网站设计 成都网站制作 成都网站建设
成都网站建设公司服务热线:028-86922220

网站建设知识

十年网站开发经验 + 多家企业客户 + 靠谱的建站团队

量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决

C#中怎么继承构造函数

这篇文章给大家介绍C#中怎么继承构造函数,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。

成都创新互联成立于2013年,是专业互联网技术服务公司,拥有项目成都网站制作、成都做网站、外贸营销网站建设网站策划,项目实施与项目整合能力。我们以让每一个梦想脱颖而出为使命,1280元洛川做网站,已为上家服务,为洛川各地企业和个人服务,联系电话:028-86922220

C#继承构造函数的示例:

using System;    namespace TestApplication   {   class Test   {   static void Main(string[] args)   {    TestA testA1 = new TestA();   Console.WriteLine("测试类A无参数构造方法");   Console.WriteLine(testA1.ToString());   Console.WriteLine();    TestA testA2 = new TestA("Set First Param");   Console.WriteLine("测试类A一个参数构造方法");   Console.WriteLine(testA2.ToString());   Console.WriteLine();    TestB testB1= new TestB();   Console.WriteLine("测试类B无参数构造方法");   Console.WriteLine(testB1.ToString());   Console.WriteLine();    TestB testB2 = new TestB("Set First Param");   Console.WriteLine("测试类B一个参数构造方法");   Console.WriteLine(testB2.ToString());   Console.WriteLine();    TestB testB3 = new TestB("Set First Param", "Set Second Param");   Console.WriteLine("测试类B两个参数构造方法");   Console.WriteLine(testB3.ToString());   Console.WriteLine();    TestB testB4 = new TestB("Set First Param",   "Set Second Param", "Set Third Param");   Console.WriteLine("测试类B三个参数构造方法");   Console.WriteLine(testB4.ToString());   Console.WriteLine();    Console.ReadLine();    }    }   ///    /// 测试类A---C#继承构造函数   ///    class TestA   {   protected string _testValueA;    ///    /// 无参数构造方法 --C#继承构造函数  ///    public TestA():this("Set First Param")   {    }    ///    /// 一个参数构造方法 --C#继承构造函数  ///    ///    public TestA(string value)   {   _testValueA = value;   }    ///    /// 重新ToString方法   ///    ///    public override string ToString()   {   return this._testValueA;   }   }    ///    /// 测试类TestB,从TestA类中继承---C#继承构造函数   ///    class TestB : TestA   {   protected string _testValueB;   protected string _testValueC;   ///    /// 调用父类中的构造方法   ///    public TestB():base()   {   this._testValueB = "Set Second Param";   this._testValueC = "Set Third Param";   }   ///    /// 调用父类中的构造方法--C#继承构造函数   ///    ///    public TestB(string valueA)   : base(valueA)   {   this._testValueB = "Set Second Param";   this._testValueC = "Set Third Param";   }    ///    /// 调用其他构造方法---C#继承构造函数   ///    ///    ///    public TestB(string valueA, string valueB)   : this(valueA, valueB, "Set Third Param")   {    }   ///    /// 三个参数的构造方法   ///    ///    ///    ///    public TestB(string valueA, string valueB, string valueC)   {   this._testValueA = valueA;   this._testValueB = valueB;   this._testValueC = valueC;   }    ///    /// 重新ToString方法 --C#继承构造函数  ///    ///    public override string ToString()   {   return this._testValueA + "\n" + this._testValueB + "\n" + this._testValueC ;   }   }   }

C#继承构造函数示例输出结果:

测试类A无参数构造方法   Set First Param    测试类A一个参数构造方法   Set First Param    测试类B无参数构造方法   Set First Param    Set Second Param   Set Third Param    测试类B一个参数构造方法   Set First Param    Set Second Param   Set Third Param    测试类B两个参数构造方法    Set First Param    Set Second Param   Set Third Param    测试类B三个参数构造方法   Set First Param    Set Second Param   Set Third Param

关于C#中怎么继承构造函数就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。


分享名称:C#中怎么继承构造函数
文章网址:http://6mz.cn/article/jdpjhp.html

其他资讯