Comment by kkukshtel
3 months ago
Something great about this release as well is the release of "file-based apps"
https://learn.microsoft.com/en-us/dotnet/csharp/fundamentals...
Basically, you can now write scripts in C# without the ceremony of a solution or project file — writing some code in a cs file and running `dotnet run myFile.cs`will execute the file directly.
You can also shebang to make it directly executable!
Hoping this inspires more people to give C# a go — it's incredible these days. Come in, the water is fine.
That's how I learned C in the 80s. Just compile the C file into an EXE. It's a good way to get started.
That said, I'm certain you've always been able to simple compile a .cs to an .exe? When I ran guerilla C# programming classes in jail, I couldn't get anything from the outside, so I was stuck with the .Net v2 csc.exe which is squirreled away in a subfolder of Windows on a default install of Visa.
What .Net 10 adds though is the ability to even scrap main() and just write code like it was Basic.
You've needed to have a project file in the past to compile .cs files, and this gets rid of that need. There are things that are part of more esoteric corners of Roslyn like .csx files that have allowed similar behavior in the past, but this fronts .cs directly as a scripting solution.
Scraping main() has been a thing for a while in dotnet — so called "Top-level programs" have be in since C# 9/.NET 5, aka about 5 years ago.
https://learn.microsoft.com/en-us/dotnet/csharp/fundamentals...
Right, I think .Net 7 brought the top-level statements to Program.cs.
The oldest version of .Net I could find on Windows 11 was .Net 4, but it still compiles just great without a project file since it has since v1:
https://www.youtube.com/watch?v=KmIwGxcMOLg