This sample shows how the command line can be accessed and two ways of accessing the array of command-line parameters.
Security Note |
---|
This sample code is provided to illustrate a concept and should not be used in applications or Web sites, as it may not illustrate the safest coding practices. Microsoft assumes no liability for incidental or consequential damages should the sample code be used for purposes other than as intended. |
To build and run the Command Line Parameters samples within Visual Studio
Open the solution (CommandLine.sln).
In Solution Explorer, right-click the CmdLine1 project, and click Set as StartUp Project.
In Solution Explorer, right-click the project, and click Properties.
Open the Configuration Properties folder, and click Debug.
In the Command Line Arguments property, type the command-line parameters (see the tutorial for an example), and click OK.
From the Debug menu, click Start Without Debugging.
Repeat the preceding steps for CmdLine2.
To build and run the Command Line Parameters samples from the Command Line
Use the Change Directory command to change to the CmdLine1 directory.
Type the following:
csc cmdline1.cs cmdline1 A B C
Use the Change Directory command to change to the CmdLine2 directory.
Type the following:
csc cmdline2.cs cmdline2 John Paul Mary