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/va_1xbet/22
https://t.me/va_1xbet/20
https://t.me/va_1xbet/24
https://t.me/s/surgut_narashchivaniye_nogtey/3
https://t.me/ah_1xbet/5
https://t.me/ah_1xbet/21
https://t.me/ah_1xbet/18
https://t.me/s/ah_1xbet/6
https://t.me/s/ah_1xbet/13
https://t.me/ah_1xbet/17
https://t.me/ah_1xbet/12
https://t.me/ah_1xbet/19
https://t.me/s/ah_1xbet/21
https://t.me/s/ah_1xbet/19
https://t.me/s/ah_1xbet/18
https://t.me/s/ah_1xbet/22
https://t.me/ah_1xbet/2
https://t.me/s/Best_rating_casino
https://t.me/reyting_topcazino/17
https://t.me/topcasino_rus/
https://t.me/top_ratingcasino/10
https://t.me/a_Topcasino/6
https://t.me/a_Topcasino/5
https://t.me/a_Topcasino/4
https://t.me/a_Topcasino/10
https://t.me/a_Topcasino/7
https://telegra.ph/Top-kazino-11-14-2
https://t.me/s/kazino_bez_filtrov
https://t.me/kazino_bez_filtrov
https://t.me/da_1xbet/5
https://t.me/da_1xbet/13
https://t.me/da_1xbet/7
https://t.me/da_1xbet/11
https://t.me/da_1xbet/6
https://t.me/da_1xbet/2
https://t.me/da_1xbet/8
https://t.me/da_1xbet/14
https://t.me/da_1xbet/3
https://t.me/da_1xbet/9
https://t.me/rq_1xbet/757
https://t.me/rq_1xbet/1247
https://t.me/rq_1xbet/834
https://t.me/s/rq_1xbet/1502
https://t.me/s/rq_1xbet/681
https://t.me/s/rq_1xbet/1194
https://t.me/s/reyting_topcazino/24
https://t.me/s/rq_1xbet/832
https://t.me/Official_1xbet1/189
https://t.me/Official_1xbet1/474
https://t.me/Official_1xbet1/346