Parse command line arguments with options

ashok.k

Member
Joined
Jun 26, 2009
Messages
13
Programming Experience
Beginner
Hi,

In a .NET console application, I want to pass parameters with options like below.

program.exe -c <config file> -t <type> -s <start date> -e <end date>

If a console program is called like above, we need to get the individual values in the progam properly even if the order of the parameters have changed.

program.exe -t <type> -c <config file> -e <end date> -s <start date>

How to parse the command line arguments with options like -t, -c ,-s etc... and get the corresponding value in the code.

Also, If an additional parameter is passed without any options i need to capture that as well in the code.



Thanks
Ashok
 
While there's nothing wrong with IanRyder's suggestion, in a Console app you will be using your own Main method as the entry point, so you can also get the commandline arguments directly as an array parameter in that, e.g.
VB.NET:
Sub Main(args As String())
 
Back
Top