Command line arguments in C#

王林
Release: 2023-09-01 16:17:02
forward
726 people have browsed it

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();
   }
Copy after login

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" -< /p>

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

The above will print -

Length of the arguments: 1
Arguments: One
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template