如果在没有命令行参数的情况下运行C#app提示参数

时间:2017-03-02 18:03:21

标签: c# console-application command-line-arguments

我有一个用于运行多个报告的应用程序,然后在运行时由命令行参数选择(在计划任务中)。但是,我希望能够在visual studio中手动运行它,然后问我想要运行什么报告。这是我试过的代码:

static void Main(string[] args)
{
      var TestVersion = false;
      int HeaderRow = 2;

      if (args.Length==0)
      {
           Console.WriteLine("What Report would you like to run?");
           args[1] = Console.ReadLine();
      }

它在args[1]行崩溃并出现以下错误:

Index was outside the bounds of the array.

我也试过了args[0],但也没有用。我也尝试过将args作为普通字符串传递。我该如何解决这个问题?

0 个答案:

没有答案