c#应用程序带参数运行


有时候我们需要让软件带参数运行,使用参数控制软件的部分行为,

C#默认窗口应用是不带参数的,不过在Main函数的参数手动加上就可以得到参数了。

举例如下:

        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main(string[] Args)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            // 检查参数
            for (int intArgIndex = 0; intArgIndex < Args.Length; intArgIndex++)
            {
                // 检查是否需要输出日志文件
                if (Args[intArgIndex] == "-log")
                    CommonVar.OutputLog = true;
            }
            
            Application.Run(new FormMain());
        }    

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM