那在子类下再创建一个孙类,创建1个孙类的对象时仍然会执行静态构造函数。按照版主的说法就可以理解了。多谢版主!
Please pay attention to the execution of the method.
This is the constructor without parameters
This is the constructor of DeriveClass
This is the constructor of GrandSun.using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;class StaticSimple
{
public static int k = 100;
static StaticSimple()
{
Console.WriteLine("Please pay attention to the execution of the method.");
}
/*static StaticSimple(string str)
{
Console.WriteLine("Only one constructor function can be made in an static class");
}
*/
public StaticSimple()
{
Console.WriteLine("This is the constructor without parameters");
}
}class DeriveClass:StaticSimple
{
public DeriveClass()
{
Console.WriteLine("This is the constructor of DeriveClass");
}
}class GrandSun : DeriveClass
{
public GrandSun()
{
Console.WriteLine("This is the constructor of GrandSun.");
} static void Main(string[] args)
{
//Console.WriteLine("The static member of class StiticSimple --k is " + StaticSimple.k);
//Console.WriteLine("The program will run.");
//DeriveClass b = new DeriveClass();
GrandSun s = new GrandSun(); Console.ReadKey();
}
}
Please pay attention to the execution of the method.
This is the constructor without parameters
This is the constructor of DeriveClass
This is the constructor of GrandSun.using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;class StaticSimple
{
public static int k = 100;
static StaticSimple()
{
Console.WriteLine("Please pay attention to the execution of the method.");
}
/*static StaticSimple(string str)
{
Console.WriteLine("Only one constructor function can be made in an static class");
}
*/
public StaticSimple()
{
Console.WriteLine("This is the constructor without parameters");
}
}class DeriveClass:StaticSimple
{
public DeriveClass()
{
Console.WriteLine("This is the constructor of DeriveClass");
}
}class GrandSun : DeriveClass
{
public GrandSun()
{
Console.WriteLine("This is the constructor of GrandSun.");
} static void Main(string[] args)
{
//Console.WriteLine("The static member of class StiticSimple --k is " + StaticSimple.k);
//Console.WriteLine("The program will run.");
//DeriveClass b = new DeriveClass();
GrandSun s = new GrandSun(); Console.ReadKey();
}
}
解决方案 »
- vs 只支持truetype字体,这不是truetype字体
- 找出对象集合中的某个对象
- 请教QQ伴侣更新速度的问题
- .net有没有这个控件
- 动态增加控件问题,请大家帮帮忙
- 求助取数据库里面单行数据的问题((1)where id=指定ID (2)count(*)/sun(score)...)
- -----------高手请进,为什么会出错----------
- 求一份VS2005用serialport类发短信的实例!
- Windows应用程序中,如何使Combobox控件不能获得焦点?或者说CanFocus怎么使用。在线等。
- 大家讨论一下怎么做基于web的小游戏。
- 新手求指导 WPF LIST问题
- 关于C#用于测试自动化开发
{
......
b();
......
}这里,代码a将工作委派给代码b去执行,这是基本的过程调用写法,没有任何新奇。而如果通过继承了的机制调用a的话,那么就会直接“消去a”而直接调用b,不再调用a。这才是继承。也有些人把委派看成是继承,可以说“从根上”对继承概念还没有理解。
http://msdn.microsoft.com/zh-cn/library/9fkccyh4.ASPX
{
return name + base.Name;
}
这就是在进行继承和委派调用的结合。