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
In you post you state:
ReplyDeleteMultiple 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?