So when you create a new .net 5 console app you just create a new from the command-line
And you get this
Which of course gives us this:
But his can be minified to this
or this, throuh the magic of C# 9
or even this:
And there we have it. The new Top-level statements in .NET 5
WHY OH WHY DEAR GOD! WHY! SAVE FROM THIS ABOMINATION!!!
We have come so far in building well structured applications, why do we want this?
Of course so we ca do this:
The world needs more hello:
This could easily be my longest post to date :)
But seriously, I do see some usages. It does provide a nice clean simple intro pathway into the “super complex” static Main method.
So what happens if you have multiple files? The compiler provides a CS8802 error which states you can’t, which makes sense. How would that get assembled? in which order?
Considering the statements gets wrapped in a main method behind the scenes, what happens with a using statement?
It works fine! Magic I tell you! Magic!
But what about the arguments you declare in Main you ask? Simple, the args are implicitly declared.
But that begs another question. How do you actually pass arguments when you use “dotnet run”.
Lets try to ask dotnet.
So this would simply be:
Maybe this would be the day I introduce my kids to .net :)