Tech Off Post

Single Post Permalink

View Thread: how to read a console application c#
  • User profile image
    Sven Groot

    Not to beat my own drum, but I made a library for parsing command line arguments:

    To use it for your example, you'd create a class as follows:

    class MyArguments
        public string UserName { get; set; }
        public string Password { get; set; }

    Then put the following code in your Main function:

    public static void Main(string[] args)
        CommandLineParser parser = new CommandLineParser(typeof(MyArguments));
            MyArguments arguments = (MyArguments)parser.Parse(args);
            // Do stuff here
        catch( CommandLineException ex )

    Big Smile