从exe中的命令行读取. [英] Read From Command Line in the exe.
本文介绍了从exe中的命令行读取.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
任何人都可以告诉我如何在c#文件中读取命令行参数.
此参数也将在我的"exe"中传递,以获取文件的路径.
提前感谢.
Anyone can tell me how to read in my c# file the command line argument.
This argument is also to be passed in my "exe" to get a path of file.
Thanx in advance.
推荐答案
取决于这是控制台应用程序还是Winforms
控制台应用程序:
将参数用于Main方法:
Depends on whether this is a Console app or a Winforms
Console app:
Use the Parameters to the Main method:
static int Main(string[] args)
{
foreach (string arg in args)
{
Console.WriteLine(arg);
}
}
WinForms应用:
WinForms app:
string[] args = Environment.GetCommandLineArgs();
if (args.Length > 1)
{
foreach (string arg in args)
{
ProcessArgument(arg);
}
}
这篇关于从exe中的命令行读取.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文