如何解析主要论点?

ped*_*ram 5 c# command-line-arguments

我怎样才能找到这些信息:

我认为我们开始了这个过程:

testFile.exe i- 100 k- "hello" j-"C:\" "D:\Images" f- "true" 
Run Code Online (Sandbox Code Playgroud)

现在,当应用程序启动时,我如何获得主要参数,所以我有:

int i = ... ; //i will be 100
string k = ... ; // k = hello
string[] path = ... ; // = path[0] = "C:\" , path[1] = "D:\Images"
bool f = ... ; // f = true;
Run Code Online (Sandbox Code Playgroud)

问候

Dar*_*rov 3

参数被传递给Main正在调用的函数:

static void Main(string[] args) 
{
    // The args array contain all the arguments being passed:
    // args[0] = "i-"
    // args[1] = "100"
    // args[2] = "k-"
    // args[3] = "hello"
    // ...
}
Run Code Online (Sandbox Code Playgroud)

参数的顺序与命令行中传递的顺序相同。如果您想使用命名参数,您可以查看这篇文章,其中建议NDesk.OptionsMono.Options

  • 是的,只不过该数组是从零开始的,而不是从一开始的。 (2认同)