.net - VB.NET Static Constructor Not Called in DLL -
i've got vb.net project has 2 classes this. 1 base of operations , 1 derived contained in seperate project dll.
public class baseclass public shared label_ string end class public class derived inherits baseclass shared sub new() baseclass.label_ = "some label" end sub public shared sub dump() end sub end class
and test code i've created
sub main() 'shared label nil here? console.writeline(derived.label_) 'shared label assigned here shared constructor called derived.dump() console.writeline(derived.label_) end sub
i finding shared constructor in derived class called when phone call instance method or phone call other static method?
my understanding shared constructor called when application run?
a static constructor called automatically initialize class before first instance created or static members referenced, not when application run.
you can't know exact moment in shared constructor called, , should'nt create assumptions it, msdn ensures points:
shared constructors run before instance of class type created. shared constructors run before instance members of construction type accessed, or before constructor of structure.type explicitly called. calling implicit parameterless constructor created structures not cause shared constructor run. shared constructors run before of type's shared members referenced. shared constructors run before types derive thetype loaded. a shared constructor not run more 1 time during single execution of program. .net vb.net oop inheritance
No comments:
Post a Comment