It is necessary that when executing arguments, for example / h and / e , the following answer appears:

Команда /h /e выполнена

or

Выполнено: /h /e

Code in Program.cs

  foreach (string arg in args) { switch (arg) { case "/h": form.Check1(); Console.Write("\r\n" + "Команда /h выполнена"); break; case "/s": form.Check2(); Console.Write("\r\n" + "Команда /s выполнена"); break; case "/e": form.Check3(); Console.Write("\r\n" + "Команда /e выполнена"); break; } } 
  • And what is the problem? - Pavel Mayorov
  • The problem is that having executed two arguments, we get two lines, but it is necessary that the arguments be listed in one line. - Vitokhv
  • So list them. - Pavel Mayorov
  • I'm new to C # so I ask experts :) - Vitokhv
  • one
    What a long epic you have with these teams ... - user236014

2 answers 2

  1. Before the cycle, we declare a list to which we will add the processed parameters:

    var processedArgs=new List<string>();

  2. In each case instead of displaying the parameter on the screen, add the processed parameter to the list:

    processedArgs.Add(arg);

  3. At the end of the cycle, glue and display:

    Console.WriteLine(String.Format("Команда {0} выполнена", String.Join(" ", processedArgs)));

  • At the third stage, for cmds writes: Cannot convert from System.Collections.Generic.List<string> to string[] - Vitokhv
  • Wrong processedArgs and not cmds - Vitokhv
  • Strange, in VS2015 I worked fine. Well, then by itself we do processedArgs.ToArray() . Although the overload that accepts IEnumerable from String.Join is: msdn.microsoft.com/ru-ru/library/dd992421(v=vs.110).aspx - Zufir

Before the loop, declare some string variable, and inside each case add on it yourself + command identifier.

If there are only 3 commands, then the string type is enough.

If there is a lot of command, it is better to use StringBuilder , which creates less work for the garbage collector.