简体   繁体   English

如何在c#中获取多行参数

[英]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? 有没有办法通过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: 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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