5 ms·
C# has had top level statements since version 9.0 (Nov 2020), and it's still just a compiler trick that produces a static method behind the scenes. Top level fu
by drewnoakes 1y ago
C# has had top level statements since version 9.0 (Nov 2020), and it's still just a compiler trick that produces a static method behind the scenes. Top level functions work too, but in a similar way.
Decompiled example: https://lab.razor.fyi/#41rAyMUVUJSfXpSYq5dcLDSRsbQ4My9dIbiyuCQ115qLyzk_rzg_J1UvvCizJNUnMy9VQykkv0AhJ7UsNUehuCSxJDU3Na9ESdOaiyskv8AHJOybWpKRn6IBEirLz0xRQBfnquZSUFBQwGtyLlgtyNhaL6bk4ihOjn-zzk9alSbAksAIAA https://lab.razor.fyi/#41rAyMUVUJSfXpSYq5dcLDSRsbQ4My9dIbiyu...
> lipstick on a pig's turd
There are several valuable compiler transformations that happen under the hood in languages like this. Closures as types, iterator/generator functions, async state machines. This is just another example.