compiler-explorer / compiler-explorer/compiler-explorer
[REQUEST]: C# compiler should default to executable when "Execute the code" is checked so that I can use top level statements
- Dominant language
- TypeScript
- Stars
- 19.1k
- Forks
- 2.1k
- Avg merge
- 3d 15h
- Merged PRs (30d)
- 67
Description
### Is your feature request related to a problem? Please describe
When I try using top-level statements in C# using .NET (main):
```c#
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
Contributor guide
Assessment
This issue has not been assessed yet.