Home  >  Article  >  Backend Development  >  Command line arguments in C#

Command line arguments in C#

王林
王林forward
2023-09-01 16:17:02722browse

C# 中的命令行参数

If you want to pass parameters through command line then use command line parameters in C#-

When we create a program in C#, use static void main, We can see the parameters.

class HelloWorld {
   static void Main(string[] args) {
      /* my first program in C# */
      Console.WriteLine("Hello World");
      Console.ReadKey();
   }

string[] args is a variable that contains all the values ​​passed from the command line as shown above.

Now to print these parameters, suppose we have a parameter "One" -

Console.WriteLine("Length of the arguments: "+args.Length);
Console.WriteLine("Arguments:");
foreach (Object obj in args) {
   Console.WriteLine(obj);
}

The above will print -

Length of the arguments: 1
Arguments: One

The above is the detailed content of Command line arguments in C#. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete