用C#解析命令行參數(shù)的最佳方法?在構(gòu)建接受參數(shù)的控制臺應(yīng)用程序時(shí),可以使用傳遞給Main(string[] args).在過去,我只是對數(shù)組進(jìn)行索引/循環(huán),并做了幾個(gè)正則表達(dá)式來提取值。然而,當(dāng)命令變得更加復(fù)雜時(shí),解析就會變得非常糟糕。所以我感興趣的是:使用的庫您使用的模式假設(shè)命令始終遵循共同標(biāo)準(zhǔn),如回答在這里.
3 回答

紫衣仙女
TA貢獻(xiàn)1839條經(jīng)驗(yàn) 獲得超15個(gè)贊
// EXAMPLE #2:// Sample for parsing the following command-line:// Test.exe /verbose /runId=10 // This sample declares a class in which the strongly-// typed arguments are populatedpublic class CommandLineArguments{ bool? Verbose { get; set; } int? RunId { get; set; }}CommandLineArguments a = new CommandLineArguments();CommandLineParser.ParseArguments(args, a);
- 3 回答
- 0 關(guān)注
- 1630 瀏覽
添加回答
舉報(bào)
0/150
提交
取消