[Mono-list] Static constructor issue

Andreas Färber andreas.faerber at web.de
Thu Sep 7 17:28:35 EDT 2006

Am 07.09.2006 um 21:07 schrieb Jonathan Gilbert:

>> The metaphor I was given way back in my student days is this:
>> Think of building a watch, you first start with the internals (gears
>> and such) and this can be seen as the Child.  Then you put on the
>> outer parts (housing, glass, etc.) where this is seen as the Parent.
>> The reason why it's different for instance ctors is because you call
>> the Parent ctor specifically before the code inside the Child ctor
>> runs.
> I'm not sure that metaphor is really useful :-)

I second that :-)

Either way this is what it is and we'll have to live with it.

> If you want to force the
> base class' static constructor to run first, then access any member  
> of the
> base class from the derived class' static constructor.

Yeah, that's what I posted earlier - list is pretty slow today...

> The reason the base
> class' static constructor is not immediately run is that the  
> inheritance
> rules involved don't apply to static members. Unlike other  
> languages, .NET
> *does* offer inheritance of static members, but the derived class  
> -- in
> terms of its static members -- is not really seen as a "kind-of"  
> the base
> class.
> To put it succinctly: The execution of Child's .cctor does not in  
> and of
> itself constitute accessing a member of Parent.

Okay, many thanks for the explanations to all of you!


More information about the Mono-list mailing list