static constructors
-
Hi everybody. There Is a way to change the initialization sequence in static constructors? I have the following code:
class MyClass { static int a; static bool b = true; static MyClass() { a = 10; } }
The compiler generates the following:class MyClass { static int a; static bool b; static MyClass() { b = true; a = 10; } }
I want that membera
will be initialized beforeb
does, but I must do it on runtime. In other words, there is some parameter that tells the compiler to place the inline initializations in the end of the static constructor? Thanks a lot, Yaakov -
Hi everybody. There Is a way to change the initialization sequence in static constructors? I have the following code:
class MyClass { static int a; static bool b = true; static MyClass() { a = 10; } }
The compiler generates the following:class MyClass { static int a; static bool b; static MyClass() { b = true; a = 10; } }
I want that membera
will be initialized beforeb
does, but I must do it on runtime. In other words, there is some parameter that tells the compiler to place the inline initializations in the end of the static constructor? Thanks a lot, YaakovNo, there isn't. It looks like your going to have to design your code around this little problem and initialize the new instance of the class yourself instead of relying on the compiler to do it for you. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
-
Hi everybody. There Is a way to change the initialization sequence in static constructors? I have the following code:
class MyClass { static int a; static bool b = true; static MyClass() { a = 10; } }
The compiler generates the following:class MyClass { static int a; static bool b; static MyClass() { b = true; a = 10; } }
I want that membera
will be initialized beforeb
does, but I must do it on runtime. In other words, there is some parameter that tells the compiler to place the inline initializations in the end of the static constructor? Thanks a lot, YaakovSimply set the value of b in the static constructor, after setting a.
-
No, there isn't. It looks like your going to have to design your code around this little problem and initialize the new instance of the class yourself instead of relying on the compiler to do it for you. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
Thanks. I have added a suggestion in the Feedback Center. Yaakov