Command Line Arguments in Visual Basic .NET
Command-line arguments are a common way to parameterize execution of programs. For example, dotnet run MyProgram.dll
uses run
and MyProgram.dll
arguments to the dotnet
program.
To experiment with command-line arguments it’s best to build the program first.
In Visual Basic .NET, we use the args
parameter of the Main
method to access command-line arguments. The Environment.GetCommandLineArgs()
method provides access to all arguments, including the program name.
Unlike in some other languages, in .NET the args
array passed to Main
doesn’t include the program name as the first element. If you need the program name, you can use Environment.GetCommandLineArgs()
or AppDomain.CurrentDomain.FriendlyName
.
Next, we’ll look at more advanced command-line processing with option parsing libraries available in .NET.