C# 实例化顺序

   static class Program
{
static void Main()
{
BaseB baseb = new BaseB();
baseb.MyFun();
Console.ReadKey();
}
}
public class BaseA
{
public static MyTest a1 = new MyTest("基类静态字段");
public MyTest a2 = new MyTest("基类字段");
static BaseA()
{
MyTest a3 = new MyTest("基类静态构造函数");
}
public BaseA()
{
MyTest a4 = new MyTest("基类构造函数");
}
public virtual void MyFun()
{
MyTest a5 = new MyTest("基类MyFun");
}
}
public class BaseB : BaseA
{
public static MyTest b1 = new MyTest("子类静态字段");
public MyTest b2 = new MyTest("子类字段");
static BaseB()
{
MyTest b3 = new MyTest("子类静态构造函数");
}
public BaseB()
{
MyTest b4 = new MyTest("子类构造函数");
}
public new void MyFun()
{
MyTest b5 = new MyTest("子类MyFun");
}
} public class MyTest
{
public MyTest(string info)
{
Console.WriteLine(info);
}
}

子类静态字段

子类静态构造函数

子类字段

基类静态字段

基类静态构造函数

基类字段

基类构造函数

子类构造函数

子类MyFun

上一篇:java OPENCV 连通域, Imgproc.findContours 例子,参数说明


下一篇:c结构体初始化问题