简体   繁体   中英

How to get multi-line parameters in c#

Is there any way to get multiple lines of parameters parsed through the main entry point in ac# application? Suppose I have this batch process:

myapp.exe (
param1
param2
param3
)

How would I get these parameters inside the console application?

myapp.exe:

using System;

namespace MyNameSpace
{
    static class Program
    {
        static void Main(string[] args)
                               // ^ Get parameters here
        {

    }
}

You can get parameters like this :

static void Main(string[] args)
{
    string param1 = args[0];
    string param2 = args[1];
    string param3 = args[2];
}

and launch the application like :

myapp.exe param1 param2 param3

If I understood correctly you are looking for something like this:

  public void Some(params int[] values)
    {
    //some code
    }

Than you can call this method as follow:

Some(1,2,3,4,5) //as many numbers as you need

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM