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
https://t.me/s/?ud_1Go/52
https://t.me/s/ud_Vodka/62
https://t.me/s/ud_Vodka/9
https://t.me/ud_Irwin/27
https://t.me/s/UD_BOoI
https://t.me/s/uD_dRagonMOneY
https://t.me/s/Ud_catcasINo
https://t.me/s/Ud_MRbiT
https://t.me/s/Ud_IZZI
https://t.me/s/uD_daddy
https://t.me/s/UD_iRWIn
https://t.me/s/official_1win_aviator/38
https://t.me/s/Beefcasino_rus
https://t.me/s/Ud_rIoBet
https://t.me/s/official_1win_aviator/95
https://t.me/s/ud_1Go
https://t.me/s/UD_VULKAN
https://t.me/s/uD_CASinO_X
https://t.me/s/ud_StaKe
https://t.me/s/tf_1win
https://t.me/s/official_1win_aviator/78
https://t.me/s/tf_1win
https://t.me/s/kta_1win
https://t.me/s/kfo_1win
https://t.me/s/Ud_StarDa
https://t.me/s/Ud_CatCasINo
https://t.me/s/UD_PInco
https://t.me/s/ud_MRbIt
https://t.me/s/uD_mArTIN
https://t.me/s/Ud_joYCASino
https://t.me/s/ud_jeT
https://t.me/s/ud_keNT
https://t.me/s/uD_KomEtA
https://t.me/s/ud_gIZbo
https://t.me/s/ud_FRESh
https://t.me/s/uD_LEgzO
https://t.me/s/ud_MOstBeT
https://t.me/s/uD_StAkE
https://t.me/s/ke_GGBet
https://t.me/s/ke_Flagman
https://t.me/s/ke_Stake
https://t.me/s/official_1win_aviator/82
https://t.me/s/ke_MostBet
https://t.me/s/ke_Pinco
https://t.me/s/ke_kent
https://t.me/s/ke_Pin_Up
https://t.me/s/ke_Starda
https://t.me/s/ke_Gizbo
https://t.me/s/ke_Booi
https://t.me/s/ke_Martin