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.
274 comments
https://t.me/Official_1xbet_1xbet/s/104
https://t.me/Official_1xbet_1xbet/s/105
https://t.me/Official_1xbet_1xbet/s/481
https://t.me/Official_1xbet_1xbet/s/1017
https://t.me/Official_1xbet_1xbet/s/1523
https://t.me/Official_1xbet_1xbet/s/1078
https://t.me/Official_1xbet_1xbet/s/480
https://t.me/Official_1xbet_1xbet/s/1020
https://t.me/Official_1xbet_1xbet/s/851
https://t.me/Official_1xbet_1xbet/s/662
https://t.me/Official_1xbet_1xbet/s/554
https://t.me/Official_1xbet_1xbet/s/468
https://t.me/Official_1xbet_1xbet/s/221
https://t.me/Official_1xbet_1xbet/s/216
https://t.me/Official_1xbet_1xbet/s/1242
https://t.me/Official_1xbet_1xbet/s/842
https://t.me/Official_1xbet_1xbet/s/1444
https://t.me/Official_1xbet_1xbet/s/308
https://t.me/Official_1xbet_1xbet/s/135
https://t.me/Official_1xbet_1xbet/s/517
https://t.me/Official_1xbet_1xbet/s/1434
https://t.me/Official_1xbet_1xbet/s/1223
https://t.me/Official_1xbet_1xbet/s/729
https://t.me/Official_1xbet_1xbet/s/604
https://t.me/Official_1xbet_1xbet/s/501
https://t.me/Official_1xbet_1xbet/s/95
https://t.me/Official_1xbet_1xbet/s/1231
**glpro**
glpro is a natural dietary supplement designed to promote balanced blood sugar levels and curb sugar cravings.
https://t.me/Official_1xbet_1xbet/s/713
https://t.me/Official_1xbet_1xbet/s/619
**sugarmute**
sugarmute is a science-guided nutritional supplement created to help maintain balanced blood sugar while supporting steady energy and mental clarity.
https://t.me/Official_1xbet_1xbet/s/351
https://t.me/Official_1xbet_1xbet/s/1550
https://t.me/Official_1xbet_1xbet/s/1358
https://t.me/Official_1xbet_1xbet/1760
https://t.me/s/Official_1xbet_1xbet/1717
https://t.me/s/Official_1xbet_1xbet/1739
https://t.me/Official_1xbet_1xbet/1602
https://t.me/s/Official_1xbet_1xbet/1758
https://t.me/s/Official_1xbet_1xbet/1605
https://t.me/s/Official_1xbet_1xbet/1755
**vitta burn**
vitta burn is a liquid dietary supplement formulated to support healthy weight reduction by increasing metabolic rate, reducing hunger, and promoting fat loss.
https://t.me/Official_1xbet_1xbet/1809
https://t.me/Official_1xbet_1xbet/1715
**synaptigen**
synaptigen is a next-generation brain support supplement that blends natural nootropics, adaptogens
**glucore**
glucore is a nutritional supplement that is given to patients daily to assist in maintaining healthy blood sugar and metabolic rates.
https://t.me/s/Official_1xbet_1xbet/1741
**prodentim**
prodentim an advanced probiotic formulation designed to support exceptional oral hygiene while fortifying teeth and gums.
https://t.me/s/Official_1xbet_1xbet/1724
https://t.me/Official_1xbet_1xbet/1614