using
System;
public class SamplesArray
{
public static void Main()
{
C c = new C();
S.C();
}
}
public static class S
{
static S() // 静态构造函数中不能有访问修饰符,默认为私有构造函数,这也是私有构造函数的用法。
{
Console.WriteLine( " 静态类S! " );
}
public static void C()
{
Console.WriteLine( " 静态类S的静态方法! " );
}
/* ~S() //静态类不能包含析构函数
{
Console.WriteLine("静态类S的析构函数!");
} */
}
public class A
{
static A()
{
Console.WriteLine( " A类的静态构造函数! " );
}
public A()
{
Console.WriteLine( " A类的实例构造函数! " );
}
~ A()
{
Console.WriteLine( " A类的析构函数! " );
}
}
public class B:A
{
static B()
{
Console.WriteLine( " B:A类的静态构造函数! " );
}
public B()
{
Console.WriteLine( " B:A类的实例构造函数! " );
}
~ B()
{
Console.WriteLine( " B:A类的析构函数! " );
}
}
public class C:B
{
static C()
{
Console.WriteLine( " C:B类的静态构造函数! " );
}
public C()
{
Console.WriteLine( " C:B类的实例构造函数! " );
}
~ C()
{
Console.WriteLine( " C:B类的析构函数! " );
}
}
public class SamplesArray
{
public static void Main()
{
C c = new C();
S.C();
}
}
public static class S
{
static S() // 静态构造函数中不能有访问修饰符,默认为私有构造函数,这也是私有构造函数的用法。
{
Console.WriteLine( " 静态类S! " );
}
public static void C()
{
Console.WriteLine( " 静态类S的静态方法! " );
}
/* ~S() //静态类不能包含析构函数
{
Console.WriteLine("静态类S的析构函数!");
} */
}
public class A
{
static A()
{
Console.WriteLine( " A类的静态构造函数! " );
}
public A()
{
Console.WriteLine( " A类的实例构造函数! " );
}
~ A()
{
Console.WriteLine( " A类的析构函数! " );
}
}
public class B:A
{
static B()
{
Console.WriteLine( " B:A类的静态构造函数! " );
}
public B()
{
Console.WriteLine( " B:A类的实例构造函数! " );
}
~ B()
{
Console.WriteLine( " B:A类的析构函数! " );
}
}
public class C:B
{
static C()
{
Console.WriteLine( " C:B类的静态构造函数! " );
}
public C()
{
Console.WriteLine( " C:B类的实例构造函数! " );
}
~ C()
{
Console.WriteLine( " C:B类的析构函数! " );
}
}
C:B类的静态构造函数!
B:A类的静态构造函数!
A类的静态构造函数!
A类的实例构造函数!
B:A类的实例构造函数!
C:B类的实例构造函数!
静态类S!//
静态类S的静态方法!
C:B类的析构函数!
B:A类的析构函数!
A类的析构函数!