c# - GetCommandLineArgs is not returning what I expected -


I have recently started studying C # through the book and I came to this example where I Command Prompt:

  Namespace Simple CSRPPP {class program {static zero main} {string [] theArgs = Environment.GetCommandLineArgs (); Foreach (ARGS string ARG) console. Videoline ("Arg: {0}", RGR); }}  

My command prompt looks like

D: \ ... \ SimpleCSharpApp \ bin \ Debug> Simple CSARPRP.exe AGR1RG2

and Output looks like this:

Arg: SimpleCSharpApp.exe

Arg: arg1

Arg: arg2

What do I think it will look like:

Arg: arg1

Arg: arg2

My question is why does string recognize my execution order as a member of logic? I hope what should I change to get the output?

I can change the prefix loop for the loop, starting from the second element like this:

  Namespace SimpleCSharpApp {class program {static zero main () { String [] theArgs = Environment.GetCommandLineArgs (); For (int i = 1; i & lt; theArgs.Length; i ++) {Console.WriteLine ("Arg: {0}", theArgs [i]); }}}}  

But it does not solve my curiosity, can I not record it as an argument to an executable file and print it with a future loop Can I expect production?

Thanks in advance!

This behavior is

array The first element in the execution program named the file name. If the file name is not available, the first element is equal to the string. The remaining elements contain any additional tokens recorded on the command line.

If you want to skip the extension extension using the first argument.

  foreach (string arg in TheArgs.Skip (1)) console. Wrightite ("Arg: {0}", arg);  

Comments

Popular posts from this blog

ios - How do I use CFArrayRef in Swift? -

eclipse plugin - Run java code error: Workspace is closed -

c - Error on building source code in VC 6 -