前言:
寫了這么久程序,今天才知道的一個基礎知識點,就是程序入口 static void Main(string[] args) 里的args參數是什么意思 ?慚愧...
需求:
點擊一個button,啟動一個exe程序(xxx.exe),並對其傳遞參數。
代碼如下:
private void btnStart_Click(object sender, RoutedEventArgs e) { var rootPath = System.Configuration.ConfigurationManager.AppSettings["rootPath"]; Process.Start(rootPath + "xxx.exe", "這是第一個參數 這是第二個參數 這是第三個參數"); }
xxx.exe的控制台代碼:
public class Program { static void Main(string[] args) { Console.WriteLine(string.Format("接收到了{0}個參數", args.Length)); foreach (var item in args) { Console.WriteLine(item); }
}
}
輸出結果:

完!
