Best way to read commandline parameters in console application

后端 未结 4 523
暗喜
暗喜 2021-01-01 14:52

Below are two ways of reading in the commandline parameters. The first is the way that I\'m accustom to seeing using the parameter in the main. The second I stumbled on wh

相关标签:
4条回答
  • 2021-01-01 15:17

    To me the first way seems more intuitive because that is how I have been doing it since my C/C++ days.

    If your commandline has one too many switches please do take a look at getopt that Thomas recommends. It's quite useful. I haven't had a look at C# port of the same though.

    Regards,

    kgr

    0 讨论(0)
  • 2021-01-01 15:20

    Do you know getopt? There is a port for C# on codeplex: http://www.codeplex.com/getopt

    0 讨论(0)
  • 2021-01-01 15:27

    Second way is better because it can be used outside the main(), so when you refactor it's one less thing to think about.

    Also I don't like the "magic" that puts the args in the method parameter for the first way.

    0 讨论(0)
  • 2021-01-01 15:34

    The first way is better because it's simpler.

    0 讨论(0)
提交回复
热议问题