首页  >  文章  >  后端开发  >  C# 中的命令行参数

C# 中的命令行参数

王林
王林转载
2023-09-01 16:17:02665浏览

C# 中的命令行参数

如果你想通过命令行传递参数,那么在C#中使用命令行参数 -

当我们在C#中创建程序时,使用static void main,我们可以看到其中的参数。

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

string[] args 是一个变量,它包含从命令行传递的所有值,如上所示。

现在要打印这些参数,假设我们有一个参数“One” -

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

上面将打印 -

Length of the arguments: 1
Arguments: One

以上是C# 中的命令行参数的详细内容。更多信息请关注PHP中文网其他相关文章!

声明:
本文转载于:tutorialspoint.com。如有侵权,请联系admin@php.cn删除