Tech Off Thread

4 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

how to read a console application c#

Back to Forum: Tech Off
  • User profile image

    Hi, can someone please help me, how could  I convert a string input in a console like:

    -u username -p password 

    to get username and password as parameters for my procedure. Can i read the input and make an '' if i fine -u put the rest of the string in the parameter username''? is this making any sens? Can someone please help, i assume that it's a very simple thing to do but I'm a begginer and I'm tring to learn Perplexed please help me!

  • User profile image

    There are much better forums for programming help. That said, the command line arguments can be found in the args parameter passed to your Main function. You can parse that yourself, or you can search Google for a command line parsing library.

  • User profile image

    @wkempf: Bing!

    Big Smile

  • 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

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.