compiler-explorer
compiler-explorer copied to clipboard
[REQUEST]: C# compiler should default to executable when "Execute the code" is checked so that I can use top level statements
Is your feature request related to a problem? Please describe
When I try using top-level statements in C# using .NET (main):
using System;
Console.WriteLine("Hello World");
I get error CS8805: Program using top-level statements must be an executable.
Describe the solution you'd like
It would be nice if the default was to use -target:exe
when "Execute the code" is checked so that I could write simple programs like that and run them (and it would be even nicer if this was the default program that appears when selecting C#, without the class and Main method, to modernize the default code).
I don't really understand how this works because if I have a class and Main method, I can run the program just fine, as if the output type was set to an executable after all? Or maybe the compiler is invoked twice, once to just compile it, without the output type being set, and afterwards in order to run it compiled again, this time correctly setting the output type?
Describe alternatives you've considered
The alternative is as it is today (having to add a class and Main method), I guess?
Additional context
Not applicable
You can check the "Link to binary" in output options. By default it compiles code in library mode.