本文共 1189 字,大约阅读时间需要 3 分钟。
1. 主要演示构造函数的继承
2. 静态构造函数
3. 示例:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
//Description: 构造函数测试
namespace NetTest
{
public class Father
{
public Father()
{
Console.Out.WriteLine("Father say");
}
public static Father()
{ }
*/
public Father(string s)
{
Console.Out.WriteLine(s + ":Father Say");
}
}
public class Son:Father
{
/*
//调用父无参构造函数类构造函数
public Son()
{
Console.Out.WriteLine("Son say");
}
*/
public Son(string s)
{
Console.Out.WriteLine("good son say:");
}
/* base显示调用父类构造函数
public Son()
: base("jack")
{
Console.Out.WriteLine("Son say");
}
*/
/*子类会隐示调用父类无参构造函数*/
/*this调用自身重载的构造函数*/
public Son()
: this("call myself another constructor")
{
Console.Out.WriteLine("above sentence calling myself");
}
}
public class TestConstructor
{
public void Test()
{
new Son();
}
}
}
本文转自敏捷的水博客园博客,原文链接http://www.cnblogs.com/cnblogsfans/archive/2008/06/11/1217410.html如需转载请自行联系原作者
王德水