C # compile the instance source code for the console with parameter programs

Source: Internet
Author: User

CMD commands such as ipconfig/all are well known, but many shoes may not know how to write such a console program with parameters. In fact, it is very simple. Let's first look at the default code for creating a project: using System; using System. collections. generic; using System. linq; using System. text; namespace _ 1 {class Program {static void Main (string [] args. We can see that a string [] args array is used to store program parameters. The parameters are separated by spaces, representing a parameter. If the parameter contains spaces, you can use the "parameter marker" to start with a double index, such as seay.exe "kill you ". Let's write an instance: using System; using System. collections. generic; using System. linq; using System. text; namespace _ 1 {class Program {static void Main (string [] args) {if (args. length <1) {Console. writeLine ("enter the parameter-a-v \" a s \ "");} else {foreach (string key in args) {if (key = "a s ") {Console. writeLine ("This is 'a s' parameters");} else if (key = "-a") {Console. writeLine ("This is 'A' parameters");} else if (key = "-v") {Console. writeLine ("This is 'V' parameters");} else {Console. writeLine ("parameter error") ;}}}} the above Code is clear, we can execute the corresponding operation according to the passed parameters

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.