我有一个WPF C#应用程序,我必须通过命令行参数.这个参数实际上是一个URL,我必须在我的应用程序中使用它?
这些命令行参数如何在WPF C#中传递,以便应用程序可以在启动期间获取URL?
lin*_*ize 57
在App.xaml.cs中
class App : Application
{
//Add this method override
protected override void OnStartup(StartupEventArgs e)
{
//e.Args is the string[] of command line argruments
}
}
Run Code Online (Sandbox Code Playgroud)
And*_*ler 31
上面的linquize已经提到了它,但我认为值得回答它自己,因为它很简单......
你可以使用:
string[] args = Environment.GetCommandLineArgs();
Run Code Online (Sandbox Code Playgroud)
这适用于应用程序中的任何位置,而不仅仅是在App.xaml.cs中