Ylbtech-languagesamples-commandline (Command line arguments)

Source: Internet
Author: User

Ylbtech-microsoft-csharpsamples:ylbtech-languagesamples-commandline (Command line arguments)

1.A, example (sample) back to top
Command line Arguments sample

This example shows how to access the command line and shows two ways to access the array of command-line arguments.

Safety Instructions

This code example is provided to illustrate a concept that does not represent the most secure coding practice, so you should not use this code example in an application or Web site. Microsoft assumes no responsibility for incidental or consequential damages arising from the use of this code sample for other purposes.

To build and run the command line arguments sample in Visual Studio
    1. Open the solution (CommandLine.sln).

    2. In Solution Explorer, right-click the CMDLINE1 project and select Set as Startup Project.

    3. In Solution Explorer, right-click the project and then select Properties.

    4. Open the Configuration Properties folder and click Debug.

    5. In the command line Arguments property, type the command-line arguments (for an example, see the Tutorial) and click OK.

    6. On the Debug menu, click Start Without Debugging.

    7. For CmdLine2, repeat the previous steps.

To build and run the command line arguments sample from the command line
    1. Use the "Change Directory" command to go to the "CmdLine1" directory.

    2. Type the following command:

      csc cmdline1.cscmdline1 A B C
    3. Use the "Change Directory" command to go to the "CmdLine2" directory.

    4. Type the following command:

      csc cmdline2.cscmdline2 John Paul Mary
1.B, sample code back to top

1.b.1, Cmdline1.cs

//Copyright (C) Microsoft Corporation. All rights reserved. //This code is published in compliance with//Microsoft Public License (MS-PL,http://opensource.org/licenses/ms-pl.html) of the terms. ////Copyright (C) Microsoft Corporation. All rights reserved. //Cmdline1.cs//parameter: A B CusingSystem; Public classcommandline{ Public Static voidMain (string[] args) {       //The Length property is used to get the lengths of the array. //Note that Length is a read-only property:Console.WriteLine ("Number of command line parameters = {0}", args.       Length);  for(inti =0; I < args. Length; i++) {Console.WriteLine ("arg[{0}] = [{1}]", I, args[i]); }   }}
View Code

1.b.2,

1.B, sample code 2 (sample codes) back to top

1.b.1, Cmdline2.cs

//Copyright (C) Microsoft Corporation. All rights reserved. //This code is published in compliance with//Microsoft Public License (MS-PL,http://opensource.org/licenses/ms-pl.html) of the terms. ////Copyright (C) Microsoft Corporation. All rights reserved. //Cmdline2.cs//parameters: John Paul MaryusingSystem; Public classcommandline2{ Public Static voidMain (string[] args) {Console.WriteLine ("Number of command line parameters = {0}", args.       Length); foreach(stringSinchargs)       {Console.WriteLine (s); }   }}
View Code

1.b.2,

1.C, (free Download) back to top

Ylbtech
Source: http://ylbtech.cnblogs.com/
This article is copyright to the author and the blog Park, Welcome to reprint, but without the consent of the author must retain this paragraph, and in the article page obvious location to the original link, otherwise reserves the right to pursue legal responsibility.

Ylbtech-languagesamples-commandline (Command-line arguments)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.