by mhh__ · 1y ago · 0 comments
You don't need to. A few years ago, C# introduced top-level statements. They were introduced in 2020, I think.
https://learn.microsoft.com/en-us/dotnet/csharp/fundamentals...
System.Console.WriteLine("Hello world!");
That's it. No namespaces (which were never required anyway, not even in C# 1.0), no classes, no functions even. If you want to define a function, you can just do so in global scope, and if it's a single expression you don't even need the braces: int Fib(int n) => (n <= 1) ? n : Fib(n - 1) + Fib(n - 2);