1. 程式人生 > >關於C#控制檯傳遞引數和接收引數

關於C#控制檯傳遞引數和接收引數

關於C#控制檯傳遞引數和接收引數

前言:

  寫了這麼久程式,今天才知道的一個基礎知識點,就是程式入口 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", "這是第一個引數 這是第二個引數 這是第三個引數");
        }

https://www.cnblogs.com/tonge/p/4417533.html

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);
            }
    }
  }

複製程式碼

 

輸出結果:

 

 

完!