Thread: C# user input

    #1
  1. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69

    C# user input


    Ok, this is probably very simple! but how do you get user input from a console window. I've been looking though learning C# and i just cant find anything at all. I was thinking something to do with System.Console or System.IO but .

    Mark.
    programming language development: www.netytan.com Hula

  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Posts
    325
    Rep Power
    12
    Hey Mark

    This is a great tutorial
    http://www.softsteel.co.uk/tutorials/cSharp/cIndex.html

    This is also great, a bit more in depth – so some obvious stuff that you’ll need to skim over, but explains some new concepts in a little more depth.
    http://www.csharp-station.com/Tutorial.aspx

    This is also great – the M$ one
    http://msdn.microsoft.com/library/de...pSpecStart.asp

    Code:
    Console.WriteLine("Enter your name");
    string s7 = Console.ReadLine();
    Console.WriteLine("Hello, {0}!", s7);
  4. #3
  5. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    Thanks Yogi, works perfectly! I'll give the tutorials a good reading a little latter

    Mark.
    programming language development: www.netytan.com Hula

  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2008
    Posts
    1
    Rep Power
    0
    Ok, that was really helpful, but what if i wanted there to be an int value or a number. What is the code for that?
  8. #5
  9. ASP.Net MVP
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Aug 2003
    Location
    WI
    Posts
    4,378
    Rep Power
    1511
    Always read from the console as a string. Then use Typname.Parse() or Typename.TryParse() to convert that to your desired type. For example, if you want an integer it would be Integer.Parse. A Decimal would be Decimal.Parse. Same for a Datetime. You can also use Convert.ToTypename() for more exotic types.
    Primary Forum: .Net Development
    Holy cow, I'm now an ASP.Net MVP!

    [Moving to ASP.Net] | [.Net Dos and Don't for VB6 Programmers]

    http://twitter.com/jcoehoorn

Similar Threads

  1. Validating user input for a database query
    By JMM in forum PHP Development
    Replies: 8
    Last Post: June 9th, 2004, 04:21 PM
  2. Wait for user input in Borland Cbuilder6
    By CFE(Rod) in forum C Programming
    Replies: 1
    Last Post: December 15th, 2003, 05:08 PM
  3. traffic IP and port ( access monitoring)
    By tiny12 in forum Linux Help
    Replies: 2
    Last Post: February 8th, 2003, 10:46 AM
  4. loss of user input from form when error received
    By amanda in forum PHP Development
    Replies: 6
    Last Post: November 15th, 2001, 02:19 AM
  5. Setting USER & PWD for *tables*??
    By Nightspirit in forum MySQL Help
    Replies: 3
    Last Post: September 26th, 2000, 06:04 AM

IMN logo majestic logo threadwatch logo seochat tools logo