방법: 명령줄 인수 가져오기
업데이트: 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;
}
}
}
}
}
명령줄 인수 검색 및 사용에 대한 예제는 명령줄 인수 처리 샘플을 참조하십시오.