I am new to the C# world but have seen other programming languages give access to command-line arguments from places like main function/method, sys.argv, etc.
It was unusual to see the following statement placed globally in the boilerplate ASP.NET Core Web App MVC (Version 6.0) Program.cs file of Visual Studio:
var builder = WebApplication.CreateBuilder(args);
Hovering over that parameter inside my IDE does seem to suggest it is indeed string[] args, but where is the entry point?
I hope someone brings in further interesting details, but as a minimum, a bit of searching yielded the following result (short answer — Top-level Statements) from Microsoft Docs:
Starting in C# 9, you can omit the
Mainmethod, and write C# statements as if they were in theMainmethod [...] For information about how to write application code with an implicit entry point method, see Top-level statements.
The page covering top-level statements makes it more clear:
argsTop-level statements can reference the
argsvariable to access any command-line arguments that were entered. Theargsvariable is never null but itsLengthis zero if no command-line arguments were provided.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With