2011-08-23 51 views
0

我想创建EXE文件,我想用C#.net我在如何创建EXE我通过在C#.net参数

传递参数如:MYEXE.EXE“你好”

请帮助

+3

什么是你的问题?在控制台应用程序中,您可以使用'args'参数访问'Main'方法中的参数。 –

+0

检出http://msdn.microsoft.com/en-us/library/acy3edy3.aspx –

+3

在谷歌上,我找到了你的[完全相同的问题] [1],这已经在代码项目中得到了解答。它就在那里,在我搜索到你的帖子的标题时得到的所有其他答案之间。 [1]:http://www.codeproject.com/Questions/244255/How-I-create-exe-in-that-I-pass-parameters-in-Csha – GolezTrol

回答

3

Main()方法参数将举行你的 “你好”:

static int Main(string[] args) 
{ 
    System.Console.WriteLine(args[0]); //this will output "hello", when you call yourApp.exe "hello" 
} 
9

使用命令参数此:

static void Main(string[] args) 
    { 
     if (args.Length > 0) 
     { 
      Console.WriteLine("You Provided " + args[0]); 
     } 

    } 

,现在你可以执行MYEXE.EXE“你好”,它会打印

您提供招呼

3

,使您的应用程序接收参数

static void Main(string [] args) 
      {   
       Application.EnableVisualStyles(); 
       Application.SetCompatibleTextRenderingDefault(false); 

       // the args is the arguments you want to pass to this application 
       Application.Run(); 

      } 

从C#调用它应用程序

static void CallProcess(string[] args) 
     { 
      Process prc= new Process(); 

      pro.StartInfo.FileName = "exe path"; 
      pro.StartInfo.Arguments = args; 

      pro.Start(); 
     }