winformアプリケーションがあり、プロジェクトプロパティの[Debug]タブの[Command Line arguments]テキストボックスに引数 "1-2-c:\ temp-test"を入力します。読み取るコードは次のとおりです。Winform appコマンドライン引数IndexOutOfRangeException
String[] arguments = Environment.GetCommandLineArgs();
string exeFilename = arguments[0];
string temp = arguments[1]; // return the argument string value. e.g."1-2-c:\temp-test"
string[] args = temp.Split('-');
try
{
string first = "", second="", third="", fourth = "";
if (args != null && args.Count() > 0)
{
first = string.IsNullOrEmpty(args[0]) ? "1" : args[0];
second = string.IsNullOrEmpty(args[1]) ? "2" : args[1];
third = string.IsNullOrEmpty(args[2]) ? @"c:\temp\" : args[2];
fourth = string.IsNullOrEmpty(args[3]) ? "test" : args[3];
}
catch(Exception ex)
{
string argsTest = "";
if (!string.IsNullOrEmpty(args[0]))
argsTest = args[0];
if (!string.IsNullOrEmpty(args[1]))
argsTest = argsTest + " "+ args[1];
if (!string.IsNullOrEmpty(args[2]))
argsTest = argsTest + " " + args[2];
if (!string.IsNullOrEmpty(args[3]))
argsTest = argsTest + " " + args[3];
MessageBox.Show(argsTest + " \n Error: " + ex.ToString());
}
私は申込書のVisual Studioを実行すると、それが正常に動作しますが、私はビン\デバッグをダブルクリックし、.exeファイルに行くとき、私はIndexOutOfRangeException例外を取得しています。
もう1つは、コマンドプロンプトからの引数を使ってこのexeを実行するとうまくいきます。
私のexeファイルをダブルクリックすると例外が発生します。
解決に時間を費やしましたが、解決には至りませんでした。私は完全に立ち往生しています。任意の種類のヒント/コード/アドバイスは相当なものです。
私はあなたを惜しまする[NDesk.Options](http://www.ndesk.org/Options)お勧めしますたくさんのトラブル。 – Filburt