C#: How to detect arguments typed into console application?

前端 未结 8 1399
长情又很酷
长情又很酷 2020-12-13 02:43

How would I go upon detecting input for a console application in C#?

Let\'s say for example I want the console application to start up by writing: Welcome To Food Hu

相关标签:
8条回答
  • 2020-12-13 03:32

    What about this case:

    mssinp.exe -cf "C:\Temp\config.txt"
    

    the value for the parameter will be splited as

    [0] 'C'
    [1] '\Temp\config.txt'
    
    0 讨论(0)
  • 2020-12-13 03:35

    I recommend Richard Lopes' Command Line Arguments Parser. It is powerful and very simple to use. Also, it accepts various ways of specifying the arguments, for example:

    • /name=Stefan
    • --name=Stefan
    • --name="Multiple words"
    • -name 'Stefan'

    Example Code:

    static void Main(string[] args)
    {
        Arguments cmdline = new Arguments(args);
    
        Console.WriteLine(cmdline["name"]);
    }
    
    0 讨论(0)
提交回复
热议问题