프로그램 자료/Visual C#

콘솔 프로그램에서 파라미터(인자값) 받기 Parser for command-line options

motolies 2016. 11. 14. 08:53




 

internal static Dictionary<string, string> argsList = new Dictionary<string, string>();

var parsedArgs = args.Select(s => s.Split(new[] { ':' })).ToDictionary(s => s[0], s => s[1]);

foreach (KeyValuePair<string, string> a in parsedArgs)

{

    if (a.Key.Contains("st") || a.Key.Contains("et"))

        argsList.Add(a.Key, ToDateType(a.Value));

    else if (!string.IsNullOrWhiteSpace(a.Value))

        argsList.Add(a.Key, a.Value);

 

}


사용은 아래와 같이 한다. 


cmd>console.exe name:"해석구역1" st:20161105 et:20161105 pipe:1 time:1 unit:h