Windows Phone Developers

Wednesday, October 22, 2008

Command Line Arguments in C#

C# Command Line Arguments

The parameter of the Main method is a String array that represents the command-line arguments. Check for the existence of the arguments by testing the Length property and iterate through the array to get the arguments

if (args.Length == 0)

{

Console.WriteLine("No Arguments Passed");

}

else

{

Console.WriteLine("Following are the arguments");

foreach (string arg in args )

{

Console.WriteLine(arg);

}

}

The arguments can also be accessed as zero-based array

Multiple arguments are split by delimiters (space). If you want to send a string like “c:\my documents\”, enclose it within double quotes.

Command Line Arguments in C#, C# Command Line Arguments, Command Line Argument Arrays in C#, Accessing command line arguments as an array using C#



Command Line Arguments in C#

See also:

Visual Basic Command Line Arguments Digg Technorati Delicious StumbleUpon Reddit BlinkList Furl Mixx Facebook Google Bookmark Yahoo
ma.gnolia squidoo newsvine live netscape tailrank mister-wong blogmarks slashdot spurl StumbleUpon

1 comment:

  1. In you post you state:

    Multiple arguments are split by delimiters (space). If you want to send a string like “c:\my documents\”, enclose it within double quotes.

    But the path example you list has \" at the end of it. This appears to break the arg parse. Is their a solution?

    ReplyDelete

kbAlertz.com :: Visual Studio 2005

kbAlertz.com :: Visual Studio 2008

kbAlertz.com :: Visual Basic 2005