In C# Console Application, Main method has a string() argument, but in VB.NET, the Main method doesn't contain the argument, if I set command line arguments, how to retrieve them?
In C#, if I right click the project and select Properties, set command line arguments in debug item, I can use args[0], args[1] and so on to achive my arguments. In VB.NET, I found
System.Environment.GetCommandLineArgs()
can also achive them, but it contains one more argument, it also contains the path of the process, anyone can help?
To set command-line arguments in Visual Studio, right click on the project name, then go to Properties. In the Properties Pane, go to "Debugging", and in this pane is a line for "Command-line arguments." Add the values you would like to use on this line.
An argument represents the value that you pass to a procedure parameter when you call the procedure. The calling code supplies the arguments when it calls the procedure. When you call a Function or Sub procedure, you include an argument list in parentheses immediately following the procedure name.
The arguments passed to the main method in C come from the command line when you execute the program. You add them when you use the command line arguments as the mechanism for passing input information from the user to the program. The program could still work if you have no command line arguments and passed nothing.
You could add them to the entry point method signature (ByVal args() As String
) and access them just as you would in C#. You could also use VB.NETs My
class to access them such as My.Application.CommandLineArgs
.
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