Easy to reproduce but realy strange to me:
Add the following 'args' with 3 strings into the Command line arguments Textbox in VisualStudio (Under Project Properties->Debug->Start Options):
-SourceFile:"c:\temp\file.txt" -DestinationFolder:"c:\temp\" -ArchiveFolder:"C:\temp\"
Test it with this simple Console Application:
class Program
{
static void Main(string[] args)
{
foreach (string t in args)
{
Console.WriteLine(t);
}
Console.ReadKey();
}
}
Result: the array (args[]) has 2 instead of 3 strings?
[0] SourceFile:c:\temp\file.txt
[1] DestinationFolder:c:\temp" -ArchiveFolder:C:\temp"
Can someone explain me why this happens? There is something strange with the quotes cause normaly, the quotes will be removed by .net, but here, there are still some quotes... but I can't see the problem...
Thanks for any help!
String []args: For accepting the zero-indexed command line arguments. args is the user-defined name. So you can change it by a valid identifier.
The args parameter stores all command line arguments which are given by the user when you run the program. If you run your program from the console like this: program.exe there are 4 parameters. Your args parameter will contain the four strings: "there", "are", "4", and "parameters"
You have a \"
in the DestinationFolder
value, which "escapes" the quote, including it in the text of the value rather than it pairing with the opening quote to close the string. You want a literal, \
, so use \\
:
-SourceFile:"c:\temp\file.txt" -DestinationFolder:"c:\temp\\" -ArchiveFolder:"C:\temp\\"
(you can even see the escaping in action in SO's highlighting engine)
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