Processing Command Line Arguments with Main

If you would rather not make use of the System.Environment type to process command-line arguments, you can define your Main() method to take an incoming array of strings. To illustrate, update your code base as follows:

Shared Sub Main(ByVal args As String()) Console.WriteLine("***** Fun with Main() *****") ' Get command-line args.

Dim s As String For Each s In args

Console.WriteLine("Arg: {0}", s) Next End Sub

When you take this approach, the first item in the incoming array is indeed the first command-line argument (rather than the name of the executable). If you were to run your application once again, you would find each command-line option is printed to the console.

Was this article helpful?

0 0

Post a comment