简体   繁体   English

命令行参数未正确返回

[英]command line arguments not returned properly

I'm totally new and study myself in c# , I found this example from internet 我是一个新手,正在使用C#学习自己,我从互联网上找到了这个例子

// cmdline1.cs
// arguments: A B C
using System;

public class CommandLine
{
   public static void Main(string[] args)
   {
       // The Length property is used to obtain the length of the array. 
       // Notice that Length is a read-only property:
       Console.WriteLine("Number of command line parameters = {0}",
          args.Length);
       for(int i = 0; i < args.Length; i++)
    {
       Console.WriteLine("Arg[{0}] = [{1}]", i, args[i]);
    }
   }
}

Output 输出量

Number of command line parameters = 3
Arg[0] = [A]
Arg[1] = [B]
Arg[2] = [C]

I tried this code on RexTester but the output is: 我在RexTester上尝试了此代码,但输出为:

Number of command line parameters = 1
Arg[0] = [parameter for the curious]

How the output will have AB and C ? 输出将如何具有AB和C?

You need to run the program from the command line. 您需要从命令行运行程序。 Open a command prompt, change directory to the bin/Debug (or bin/Release, depending on how you bulit it) directory and run your command like so: 打开命令提示符,将目录更改为bin / Debug(或bin / Release,具体取决于您如何使用它)目录,然后按以下方式运行命令:

commandline.exe A B C

The output will have A , B , and C because you specify that when you run the program. 输出将具有ABC因为您在运行程序时指定了该名称。

If you run the program outside the debugger, you do this simply by providing those values on the command line. 如果在调试器之外运行程序,则只需在命令行上提供这些值即可。 For example: 例如:

CommandLine ABC 命令行ABC

If you are running the program in Visual Studio using the debugger, you can provide the command line arguments in the "Debug" pane of the Project Properties window. 如果要使用调试器在Visual Studio中运行程序,则可以在“项目属性”窗口的“调试”窗格中提供命令行参数。 Just enter then in the "Command line arguments" text box, exactly as you would have provided them on the command line (without the executable name itself, of course). 只需在“命令行参数”文本框中输入,然后完全按照在命令行上提供它们的方式输入(当然,没有可执行文件名称本身)。

If you are running the program via the RexTester utility, then I have no idea how you provide command line arguments. 如果您通过RexTester实用程序运行该程序,那么我不知道如何提供命令行参数。 It's not possible as far as I know (but I could be missing something). 据我所知,这是不可能的(但是我可能会丢失一些东西)。

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

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