The parameter args__ function in the main function of the C # console Application

Source: Internet
Author: User

Original source: http://chenyansong4321.blog.163.com/blog/static/7994995620085305482709/
The main function is the entry point for the C # application, and the main function can have four signatures, as follows:

static void Main ()

static void Main (string[] args)

static int Main ()

static int Main (string[] args)

Executing this function is executing the application. And this function has a parameter string[] args, now we're going to pee it.

The parameter of the main function string[] args is a way to receive information from outside the application. This information is specified when the program is run, and the parameter is represented by command-line arguments.

XXXX about command line parameter xxxx

Open a Notepad, you can enter Notepad in the command line window, you can run this program, but you can also enter Notepad MyFile.txt, the result is that the Notepad runtime loads MyFile.txt, and if the file does not exist, Notepad will create the file. And the myfile.txt here is the command-line argument. With the args parameter, you can write a console application that works in the same way.

When the console application is executed, any command-line arguments specified are placed in the args array, which can then be invoked when the application requires it.

Here is an example to illustrate:

class Class1

{

static void Main (string[] args)

{

Console.WriteLine ("{0} command line arguments were specified", args.length);

foreach (String arg in args)

{

Console.WriteLine (ARG);

}

}

}

Then select Properties in the Solution window, select the configuration propertie option, and then select the Debugging (Debug) page, and set the command line arguments that you want in command-line arguments

For example, setting: Anika pingie myfile.txt (separated by "space" between parameters)

Then, when Ctrl+f5 runs this program, it will output Anika Pingie in turn myfile.txt

This should be on the args parameter, have some understanding of it. :-)

====================================================

Project-> (project name) Properties-> Debug-> command-line arguments

1. Execute at command line

Parameters are separated by a space, if the argument has spaces, in double quotes style

Test AA "BB cc" CC

The equivalent of three parameters passed.

2. Add parameters to VS2005

Menu items--Your project Properties--Debugging--Startup options--command line arguments

You can also type your command-line arguments here

Related Article

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.