2017-08-04 35 views
-2

我想啓動我的程序時使用啓動參數。例如:C# - 如何使用啓動參數

c:\my.exe -arg1 

像一些程序使用的參數,如:

-silent 

如果搜索信息,但找不到任何幫助。 謝謝!

回答

0

在C#中的方法

public static void Main(string[] args) 

獲取的這array of strings - args從命令prompth參數。

例如:

public static class Program 
{ 
    public static void Main(string[] args) 
    { 
     foreach(var arg in args) 
     { 
      Console.WriteLine("You entered parameter: " + arg); 
     } 

     Console.ReadLine(); 
    } 
} 

並嘗試編譯和運行通過該PROGRAMM:

program Hello World 

輸出將是:

You entered parameter: Hello 
You entered parameter: World