那在子类下再创建一个孙类,创建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();
    }
}

解决方案 »

  1.   

    你不要把“继承”跟“委派”概念搞混了。比如说void a()
    {
        ......
        b();
        ......
    }这里,代码a将工作委派给代码b去执行,这是基本的过程调用写法,没有任何新奇。而如果通过继承了的机制调用a的话,那么就会直接“消去a”而直接调用b,不再调用a。这才是继承。也有些人把委派看成是继承,可以说“从根上”对继承概念还没有理解。
      

  2.   


    http://msdn.microsoft.com/zh-cn/library/9fkccyh4.ASPX
      

  3.   

    如果你在msdn的那个示例代码上,再写上        get
            {
                return name + base.Name;
            }
    这就是在进行继承和委派调用的结合。