static void Main(string[] args)

Started by
6 comments, last by nobodynews 14 years, 6 months ago
what does the args imply? what is in args? static void Main(string[] args)
Advertisement
When you run your program from the command line, like "myProgram -flag1 -flag2", args[] will contain "-flag1" and "-flag2". It is used for example if you want the user to be able to specify a file-name or something that will be used by your program.
it's everything passed to you application on the commande line or with a shortcut.

ex: myprogram.exe /swith1 /switch2

args[0] = myprogram.exe
args[1] = /switch1
args[2] = /switch2
Quote:Original post by matchu
it's everything passed to you application on the commande line or with a shortcut.

ex: myprogram.exe /swith1 /switch2

args[0] = myprogram.exe
args[1] = /switch1
args[2] = /switch2


In the case of C# the program name is not the first argument passed.
Mike Popoloski | Journal | SlimDX
eh.. also i am trying to run a program with visual studio. But it does not respond. How do i track which statement is it stuck at?
Quote:Original post by Erik Rufelt
When you run your program from the command line, like "myProgram -flag1 -flag2", args[] will contain "-flag1" and "-flag2". It is used for example if you want the user to be able to specify a file-name or something that will be used by your program.


but i just do the normal run after building. But how come the args.length is 2?
Quote:Original post by TeSsL
eh.. also i am trying to run a program with visual studio. But it does not respond. How do i track which statement is it stuck at?


by running it in the debugger and pressing Shift+F5 to stop running the program. You should also learn the other debugger options/commands at your disposal.

C++: A Dialog | C++0x Features: Part1 (lambdas, auto, static_assert) , Part 2 (rvalue references) , Part 3 (decltype) | Write Games | Fix Your Timestep!

Quote:Original post by TeSsL
Quote:Original post by Erik Rufelt
When you run your program from the command line, like "myProgram -flag1 -flag2", args[] will contain "-flag1" and "-flag2". It is used for example if you want the user to be able to specify a file-name or something that will be used by your program.


but i just do the normal run after building. But how come the args.length is 2?


Set a breakpoint at the start of the program and look at the locals window and you would see what is being passed to args.

C++: A Dialog | C++0x Features: Part1 (lambdas, auto, static_assert) , Part 2 (rvalue references) , Part 3 (decltype) | Write Games | Fix Your Timestep!

This topic is closed to new replies.

Advertisement