ph91.de
  • Home
  • About me
  • Categories
    • Software Development
    • New Zealand
    • Music
    • Tech & IT
    • Sports
    • Dublin
    • Junk
  • Contact
  • Disclaimer
ph91.de
ph91.de
  • Home
  • About me
  • Categories
    • Software Development
    • New Zealand
    • Music
    • Tech & IT
    • Sports
    • Dublin
    • Junk
  • Contact
  • Disclaimer
  • Software Development

Unexpected C# Behaviour

  • 16. September 2018
  • Philipp

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.

 

Related Topics
  • c#
  • compiler
  • ecma
  • language
  • static
Philipp

Previous Article
  • Tech & IT

Configure a postfix mailserver correctly (1blu)

  • 10. September 2018
  • Philipp
View Post
Next Article
  • Software Development

Design Patterns Game

  • 30. April 2019
  • Philipp
View Post
549 comments

Comments navigation

Older comments
  1. JamesJex says:
    16. November 2025 at 01:07

    https://t.me/s/Official_1xbet1/1404

  2. JamesJex says:
    16. November 2025 at 02:22

    https://t.me/s/Official_1xbet1/1417

  3. JamesJex says:
    16. November 2025 at 03:35

    https://t.me/Official_1xbet1/110

  4. JamesJex says:
    16. November 2025 at 04:46

    https://t.me/Official_1xbet1/1027

  5. JamesJex says:
    16. November 2025 at 05:59

    https://t.me/s/Official_1xbet1/1274

  6. Justinpah says:
    19. November 2025 at 09:18

    https://t.me/Topcasino_licenziya/30

  7. Justinpah says:
    19. November 2025 at 12:56

    https://t.me/s/Topcasino_licenziya/32

  8. Justinpah says:
    19. November 2025 at 14:11

    https://t.me/s/kazino_s_licenziei/2

  9. Justinpah says:
    19. November 2025 at 15:24

    https://t.me/Topcasino_licenziya/6

  10. Justinpah says:
    19. November 2025 at 16:40

    https://t.me/Topcasino_licenziya/26

  11. Justinpah says:
    19. November 2025 at 17:57

    https://t.me/s/Topcasino_licenziya/39

  12. Javierbub says:
    19. November 2025 at 19:34

    https://t.me/s/top_online_kazino/6

  13. Charleswrics says:
    19. November 2025 at 20:56

    https://t.me/s/top_online_kazino/4

  14. Charleswrics says:
    19. November 2025 at 22:14

    https://t.me/s/top_online_kazino/8

  15. Charleswrics says:
    19. November 2025 at 23:24

    https://t.me/s/reyting_luchshikh_kazino

  16. Charleswrics says:
    20. November 2025 at 00:33

    https://t.me/top_online_kazino/6

  17. Charleswrics says:
    20. November 2025 at 01:39

    https://t.me/top_online_kazino/5

  18. Charleswrics says:
    20. November 2025 at 02:46

    https://t.me/top_online_kazino/9

  19. Charleswrics says:
    20. November 2025 at 03:53

    https://t.me/s/top_online_kazino/10

  20. Terryraf says:
    20. November 2025 at 09:53

    https://cse.google.co.ve/url?sa=t&url=https://t.me/Official_1xbet_1xbet/1291

  21. Terryraf says:
    20. November 2025 at 11:30

    https://cse.google.ee/url?sa=t&url=https://t.me/Official_1xbet_1xbet/1245

  22. Terryraf says:
    20. November 2025 at 13:18

    http://lifewealthadvisor.com/__media__/js/netsoltrademark.php?d=https://t.me/Official_1xbet_1xbet/1652

  23. WilliamThova says:
    20. November 2025 at 13:31

    https://www.avito.ru/surgut/predlozheniya_uslug/apparatnyy_manikyur_i_pedikyur_s_pokrytiem_4030660549?utm_campaign=native&utm_medium=item_page_ios&utm_source=soc_sharing_seller

  24. Terryraf says:
    20. November 2025 at 15:07

    http://archityke.com/__media__/js/netsoltrademark.php?d=https://t.me/s/Official_1xbet_1xbet/980

  25. Terryraf says:
    20. November 2025 at 16:58

    http://ip50.ofac.com/__media__/js/netsoltrademark.php?d=https://t.me/s/Official_1xbet_1xbet/742

  26. Santonip says:
    20. November 2025 at 19:39

    https://t.me/s/om_1xbet/11

  27. Santonip says:
    20. November 2025 at 21:00

    https://t.me/top_casino_rating_ru/9

  28. Santonip says:
    20. November 2025 at 22:14

    https://t.me/om_1xbet/7

  29. Santonip says:
    20. November 2025 at 23:27

    https://t.me/top_casino_rating_ru/14

  30. Santonip says:
    21. November 2025 at 00:43

    https://t.me/s/om_1xbet/10

  31. Santonip says:
    21. November 2025 at 03:08

    https://t.me/om_1xbet/11

  32. Santonip says:
    21. November 2025 at 04:20

    https://t.me/s/om_1xbet/9

  33. Santonip says:
    21. November 2025 at 05:31

    https://t.me/top_casino_rating_ru/7

  34. Santonip says:
    21. November 2025 at 06:44

    https://t.me/top_casino_rating_ru/10

  35. Santonip says:
    21. November 2025 at 08:00

    https://t.me/s/om_1xbet/7

  36. Santonip says:
    21. November 2025 at 09:15

    https://t.me/s/om_1xbet/15

  37. Santonip says:
    21. November 2025 at 10:30

    https://t.me/om_1xbet/15

  38. RouletteRogue says:
    21. November 2025 at 11:47

    https://t.me/of_1xbet/313

  39. JoshuaLiecy says:
    21. November 2025 at 16:59

    Регистрируйтесь прямо сейчас на 1win, чтобы активировать 1win ваучер сайт и получать до 100% бонуса за первый депозит! В онлайн-казино вас ждут свежие слоты и фриспины, ставки на спорт с высокими коэффициентами и лайв-ставки, а также быстрый вывод выигрышей и кэшбэк до 15%. Наслаждайтесь простотой входа, минимальным депозитом от 10 рублей и круглосуточным доступом для реальных побед и выгодных предложений!

  40. JoshuaLiecy says:
    21. November 2025 at 22:40

    1win зеркало сайта актуальное — заходи прямо сейчас и открывай для себя крупнейшее онлайн-казино и букмекерскую платформу с высокими коэффициентами и мгновенным выводом выигрышей! Получи бонус за депозит до 5000 ?, фриспины в слотах, ставки на спорт с лайв-режимом, кэшбэк до 10%, а также быстрый доступ к личному кабинету круглосуточно. Минимальный депозит — всего 100 ?, обеспечивая легкий старт и возможность быстро увеличивать свой выигрыш!

  41. JoshuaLiecy says:
    22. November 2025 at 04:05

    1 win что это — начни выигрывать прямо сейчас! В 1win доступны лучшие онлайн казино с слотами и фриспинами, ставки на спорт с высокими коэффициентами и лайв-ставки в реальном времени. Получай бонусы за депозит до 10 000 ?, используй промокод для фриспинов и кэшбэк до 15%, а быстрая регистрация и минимальный депозит от 100 ? позволяют вывести выигрыш в пару кликов — круглосуточный доступ и быстрые выплаты делают игру максимально выгодной и доступной!

  42. AllInAce says:
    22. November 2025 at 20:57

    https://t.me/s/ef_beef

  43. 1winLiecy says:
    23. November 2025 at 10:43

    https://t.me/s/Official_Ru_1WIN

  44. beefLiecy says:
    25. November 2025 at 22:53

    https://telegra.ph/Beef-kazino-11-25

  45. PokerdomInode says:
    1. December 2025 at 16:12

    https://t.me/s/officials_pokerdom/3621

  46. MartincasinoInode says:
    2. December 2025 at 21:29

    https://t.me/Martin_officials

  47. slots2345game says:
    6. December 2025 at 09:04

    Yo, slots2345game is my jam! Been hitting it up after work and sometimes the afteroon, you know. Solid selection, no lag. Check it out! slots2345game

  48. beefcasino says:
    7. December 2025 at 11:23

    https://t.me/s/Beefcasino_officials

  49. MartinCasino says:
    8. December 2025 at 09:08

    https://t.me/s/Martin_casino_officials

Comments navigation

Older comments

Leave a Reply

Your email address will not be published. Required fields are marked *

Dev profiles
  • BitBucket
  • Github
  • Stackoverflow
Side Projects
  • NMF
  • Speed-kini.de
  • Sudoku Solver
  • Windwarner
Archive
ph91.de
Blog by Philipp Schreitmüller

Input your search keywords and press Enter.