The problem is that you can't do that: the
static
constructor for B is not called until an instance of B is first used.
So if an instance of A is constructed:
A a = new A();
Then the value of the
keyName
property is never initialized (and thus
null
).
One way to get round this - sort of - would be to declare the class
A
as
abstract
, which would prevent instances of A being constructed, but even then the constructor for
A
will be called before the constructor for
B
(as you would expect,
A
has to be "complete" before
B
can use it) which would still mean that
keyName
is not initialised before
Initial
is called.
You can't do what you want: it just isn't possible because the class
A
constructor has to be complete before any derived class
constructor
code can be executed - and that applies equally to instance and static constructors.
What are you trying to achieve that you think you need this?