wpf怎样获取控制台命令行参数
1个回答
展开全部
下面的代码演示如何使用 Applichttp://www.wpf123.comation 和 Startup 事件获取命令行参数。
<Application x:Class="CSharp.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Startup="app_Startup" > </Application>
C#:
using System;
using System.Windows;
namespace CSharp
{
public partial class App : Application
{
void app_Startup(object sender, StartupEventArgs e)
{
// If no command line arguments were provided, don't process them
if (e.Args.Length == 0) return;
// Get command line arguments
foreach (string argument in e.Args)
{
switch (argument)
{
case "arg1":
// Process arg 1
break;
case "arg2":
// Process arg 2
break;
case "arg3":
// Process arg 3
break;
}
}
}
}
}
<Application x:Class="CSharp.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Startup="app_Startup" > </Application>
C#:
using System;
using System.Windows;
namespace CSharp
{
public partial class App : Application
{
void app_Startup(object sender, StartupEventArgs e)
{
// If no command line arguments were provided, don't process them
if (e.Args.Length == 0) return;
// Get command line arguments
foreach (string argument in e.Args)
{
switch (argument)
{
case "arg1":
// Process arg 1
break;
case "arg2":
// Process arg 2
break;
case "arg3":
// Process arg 3
break;
}
}
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询