别的程序调用我的exe程序(C#编的),在调用的时候会给我传一个参数,我怎么能在程序运行之前先获取到这个参数?比如说别的程序这样调用我的exe程序:Process.Start("c:\\windows\\system32\\XXX.exe", "-s -t "); 
我的程序初始化的时候需要获取到后面的参数。

解决方案 »

  1.   

    在Program的Main函数可以写为这样的形式static void Main(string[] args),得到的参数全放到args中了,你只要对args操作就可以了
      

  2.   

    比如你的exe文件是test.exe
    你的程序中的main函数是:
    public static void Main(string[] args)
    {
    //可以通过下标访问传的参数,如args[0]
    }
    在cmd下,调用时传参数: test.exe 1 2 
    //将1 2传给exe了 
      

  3.   

    用下面的语句可以获得参数:
    string[] argv = Environment.GetCommandLineArgs();