.NET 6.0 C# “new console template” – how to read CLI arguments?

You can access the command line arguments from anywhere in your code using the Environment class.

In particular, you can use Environment.GetCommandLineArgs:

string name = Environment.GetCommandLineArgs()[1];
Console.WriteLine($"Hello, {name}!");

Note that the first element in the array contains the path of the executable and the arguments passed to the program start with the second element, i.e. at index 1.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)