Ant*_*bry 23 .net command-line dependencies
我正在编写一个需要解析进程命令行的.NET类.我不希望Main()方法和该类之间存在依赖关系.该类如何访问命令行?
ito*_*son 41
打电话Environment.GetCommandLineArgs().
如果您使用.NET Compact Framework,则未实现 Environment.GetCommandLineArgs() 方法,并且 System.Diagnostics.Process.GetCurrentProcess().StartInfo.Arguments 始终返回空字符串,因此您必须使用 main 函数并将参数传递给其他类。
一个例子 :
[MTAThread]
static void Main(String[] commandLineArguments)
{
CommandLineHelper.parse(commandLineArguments);
}
public static class CommandLineHelper
{
public static void parse(String[] commandLineArguments) {
// add your code here
}
}
Run Code Online (Sandbox Code Playgroud)