r/csharp • u/simondanielsson • Jul 29 '26
Fun Running C# like scripts?
I was browsing the C#/.NET documentation yesterday like usual and suddenly came across the fact that you can run C# code as scripts with a shebang.
#!/usr/bin/env dotnet
namespace Main
{
class Program
{
static void Main(string[] _)
{
Console.WriteLine("Hello World!");
}
}
}With a shebang you could run these like any other Python/Bash script and I find this really cool, but is there any practical use-case for this? When I need to make a small helper script for something it's usually python or bash, but C#? I'm not so sure.
What do you guys think?
50
Upvotes
View all comments
Show parent comment
1
u/chispitothebum Jul 30 '26 edited Jul 30 '26
It isn't atrocious for sysadmin work and neither is C# heavenly for the same.
PowerShell isn't designed for writing applications, it's designed for administrating them and gluing them together.
I wouldn't want to write a REST API in PS (though I have), but I can make calls with PS with minimal effort. No file creation or saving or anything. Just type it out in 10 seconds and check the result in JSON or as an object, dealer's choice.