I recently stumbled across the unexpected behavior of C# when dealing with static variables. I put it a green unit test:
private static string a = $"a{b}";
private static string b = $"b{2+100}";
private static string c = $"{b}c";
[Test]
public void Test()
{
Assert.AreEqual("a",a);
Assert.AreEqual("b102c", c);
Assert.AreEqual(10, ReturnSum()(2,3));
}
As C# has an ECMA definition, this behavior is described in there (reference found here):
17.11: The execution of a static constructor is triggered by the first of the following events to occur within an application domain:
- An instance of the class is created.
- Any of the static members of the class are referenced.
If a class contains the Main method (§10.1) in which execution begins, the static constructor for that class executes before the Main method is called. If a class contains any static fields with initializers, those initializers are executed in textual order immediately prior to executing the static constructor (§17.4.5).
Despite that, it is quite weird that the compiler doesn’t warn you if a static member is referencing a static member which is executed later.
505 comments
**hepatoburn**
hepatoburn is a potent, plant-based formula created to promote optimal liver performance and naturally stimulate fat-burning mechanisms.
https://t.me/s/ke_Vulkan
https://t.me/s/ke_Casino_X
https://t.me/s/ke_CatCasino
https://t.me/s/ke_Vodka
https://t.me/s/ke_1Win
https://t.me/s/ke_Irwin
https://t.me/s/ke_Daddy
https://t.me/s/ke_PlayFortuna
https://t.me/s/kef_Lex
https://t.me/s/ke_Leon
https://t.me/s/kef_Rox
https://t.me/s/ke_Volna
https://t.me/s/kef_R7
https://t.me/s/ke_Drip
https://t.me/s/ke_mellstroy
https://t.me/s/ke_Sol
https://t.me/s/ke_1xbet
https://t.me/s/ke_Riobet
https://t.me/s/ke_Jet
https://t.me/s/ke_Gama
https://t.me/s/official_1win_aviator/201
https://t.me/s/ke_JoyCasino
https://t.me/s/ke_DragonMoney
https://t.me/official_1win_aviator/288
https://t.me/s/ke_MrBit
https://t.me/s/ke_Fresh
https://t.me/s/topcasino_v_rossii
https://t.me/s/top_kazino_z
https://t.me/s/a_Top_onlinecasino/19
https://t.me/a_Top_onlinecasino/8
https://t.me/s/a_Top_onlinecasino/3
https://t.me/a_Top_onlinecasino/19
https://t.me/a_Top_onlinecasino/10
https://t.me/s/a_Top_onlinecasino/17
https://t.me/a_Top_onlinecasino/5
https://t.me/s/a_Top_onlinecasino/4
https://t.me/a_Top_onlinecasino/21
https://t.me/a_Top_onlinecasino/7
https://t.me/topcasino_rus/
https://t.me/s/official_R7_es
https://t.me/s/official_CasinoX_es
https://t.me/s/official_Lex_es
https://t.me/s/official_Stake_es
https://t.me/s/official_MostBet_es
https://t.me/s/official_1xbet_ed
https://t.me/s/official_Flagman_es
https://t.me/s/official_MrBit_es
https://t.me/s/official_Jet_ed
https://t.me/s/official_Izzi_ed