using System;
namespace TestInherit
{
public class Father
{
public int father_a = 111;
public int father_aa = 1111;
public readonly int father_c = 7777;
public static int father_e = 222;
public static int father_ee;
static Father()
{
father_e = 5555;
father_ee = 3333;
} public Father()
{
father_ee = 4444;
}
public Father(int a)
{
father_a = a;
}
}
public class Son: Father
{
public int son_int = 9999;
public static int son_b = 111;
public static int son_c;
public Son()
{
son_c = 222;
}
static Son()
{
son_c = 333;
}
public Son(int a)
{
son_int = a;
}
}
class Class1
{
[STAThread]static void Main(string[]args)
{
Son son1 = new Son();
}
}
}
在vs中点击F11,静态构造函数始终不执行,这是为何?静态构造函数不是始终优先于非静态执行的么?
namespace TestInherit
{
public class Father
{
public int father_a = 111;
public int father_aa = 1111;
public readonly int father_c = 7777;
public static int father_e = 222;
public static int father_ee;
static Father()
{
father_e = 5555;
father_ee = 3333;
} public Father()
{
father_ee = 4444;
}
public Father(int a)
{
father_a = a;
}
}
public class Son: Father
{
public int son_int = 9999;
public static int son_b = 111;
public static int son_c;
public Son()
{
son_c = 222;
}
static Son()
{
son_c = 333;
}
public Son(int a)
{
son_int = a;
}
}
class Class1
{
[STAThread]static void Main(string[]args)
{
Son son1 = new Son();
}
}
}
在vs中点击F11,静态构造函数始终不执行,这是为何?静态构造函数不是始终优先于非静态执行的么?
2.static Father();
3.Father();
4.Son();
Partition I:
Concepts and Acrchitecture1-4 略
5. Execution of any type's initializer method will not trigger automatic execution of any initializer methods defined by its base type, not of any interfaces that the type implements
------------------------------------------------------------------------------
args {string[0]} string[]
- son1 null TestInherit.Son
- 静态成员
son_b 0 int
son_c 0 int----------------------------------------------------------------------------
再按一下
--------------------------------------------------------------------------
- this {TestInherit.Son} TestInherit.Son
- base {TestInherit.Son} TestInherit.Father {TestInherit.Son}
father_a 0 int
father_aa 0 int
father_c 0 int
- 静态成员
father_e 0 int
father_ee 0 int
son_int 0 int
- 静态成员
son_b 111 int
son_c 333 int
-----------------------------------------------------
进入Father类
- this {TestInherit.Son} TestInherit.Father {TestInherit.Son}
- [TestInherit.Son] {TestInherit.Son} TestInherit.Son
- base {TestInherit.Son} TestInherit.Father {TestInherit.Son}
father_a 0 int
father_aa 0 int
father_c 0 int
- 静态成员
father_e 5555 int
father_ee 3333 int
son_int 9999 int
- 静态成员
son_b 111 int
son_c 333 int
father_a 0 int
father_aa 0 int
father_c 0 int
- 静态成员
father_e 5555 int
father_ee 3333 int
--------------------------------------------------------------------------------------
- this {TestInherit.Son} TestInherit.Father {TestInherit.Son}
- [TestInherit.Son] {TestInherit.Son} TestInherit.Son
- base {TestInherit.Son} TestInherit.Father {TestInherit.Son}
father_a 111 int
father_aa 1111 int
father_c 7777 int
- 静态成员
father_e 5555 int
father_ee 4444 int
son_int 9999 int
- 静态成员
son_b 111 int
son_c 333 int
father_a 111 int
father_aa 1111 int
father_c 7777 int
- 静态成员
father_e 5555 int
father_ee 4444 int
------------------------------------------------------------------------------------------- this {TestInherit.Son} TestInherit.Son
- base {TestInherit.Son} TestInherit.Father {TestInherit.Son}
father_a 111 int
father_aa 1111 int
father_c 7777 int
- 静态成员
father_e 5555 int
father_ee 4444 int
son_int 9999 int
- 静态成员
son_b 111 int
son_c 222 int
-------------------------------------------------------------------------------
结束前
args {string[0]} string[]
- son1 {TestInherit.Son} TestInherit.Son
- base {TestInherit.Son} TestInherit.Father {TestInherit.Son}
father_a 111 int
father_aa 1111 int
father_c 7777 int
- 静态成员
father_e 5555 int
father_ee 4444 int
son_int 9999 int
- 静态成员
son_b 111 int
son_c 222 int
---------------------------------------------------------------