方法 : コマンド ライン引数を取得する

更新 : 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;
                }
            }
        }
    }
}

コマンド ライン引数の取得および使用の例については、「コマンド ライン引数の処理のサンプル」を参照してください。

参照

処理手順

コマンド ライン引数の処理のサンプル