更新:2007 年 11 月
這個範例顯示如何取得已傳遞至應用程式的命令列引數。
範例
下列程式碼範例會示範如何使用 Application 和 Startup 事件來取得命令列引數。
<Application
x:Class="CSharp.App"
xmlns="https://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="https://schemas.microsoft.com/winfx/2006/xaml"
Startup="app_Startup"
>
</Application>
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;
}
}
}
}
}
如需擷取和使用命令列引數的範例,請參閱處理命令列引數範例。