首頁  >  文章  >  後端開發  >  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刪除