0

What I want to be able to do is create a display in the console that shows this:


Name:

Date:

Birthday:


And after data is entered next to each of the colons and enter is pressed, It activates a method of some sort that would set variables to the data. How do I do this?

Response to first few comments:

Well, the reason why i am using console is because i am trying to learn C# and i am trying to do this the same way I learned for C, by starting with the console. I thought this would be the easiest way to display the program for the user. From the comments above, it seems I need to learn something else.

Rahul Shah
  • 141
  • 2
  • 12
  • 2
    You can't do that, in a console app. You can prompt for name, then date, then birthday - but you can't display all three prompts at once and have the user "fill them in". – Blorgbeard Jul 14 '15 at 02:58
  • I disagree with @Blorgbeard, you can. Set the cursor position, write out the prompts, then set the cursor position to the first one, read key-by-key until you get an enter/tab, then go to the next field and repeat. The question though is why use a console app when this is trivially easy in Winforms or any other windowing UI? – Ron Beyer Jul 14 '15 at 02:59
  • You would have to add quite a few things including a _message pump_ but by which time it's arguably no longer a console app. So you may be better off doing a WinForms app in the first place –  Jul 14 '15 at 02:59
  • `Console.WriteLine` / `Console.ReadLine` - is this really hard? – T.S. Jul 14 '15 at 03:00
  • possible duplicate of [Read user input from console](http://stackoverflow.com/questions/7280591/read-user-input-from-console) – T.S. Jul 14 '15 at 03:01
  • Well, the reason why i am using console is because i am trying to learn C# and i am trying to do this the same way I learned for C, by starting with the console. I thought this would be the easiest way to display the program for the user. From the comments above, it seems I need to learn something else. – Rahul Shah Jul 14 '15 at 03:09
  • For a console UI-like interactive 'form' use a library such as an ncurses-clone; or better, a library on top of such. – user2864740 Jul 14 '15 at 03:09
  • 2
    @T.S.: that question is already closed, just you to remind. – abatishchev Jul 14 '15 at 04:13

2 Answers2

2

Maybe I'm wrong but this is my interpretation of your question:

Console.Write("Name: ");
var name=Console.ReadLine();
Console.Write("Date: ");
var a = Console.ReadLine();
var date = DateTime.Parse(a);
Console.Write("Birthday: ");
var b = Console.ReadLine();
var birthday = DateTime.Parse(b);

I know my code is badly-written, but it can do what you want, except line-by-line instead of "create a display" and type it in.

ProudNoob
  • 77
  • 2
  • 13
1
Console.Write("Name: ");
string name = Console.ReadLine();
Console.Write("Date: ");
string d = Console.ReadLine();
string date = DateTime.Parse(d);
Console.Write("Birthday: ");
string b = Console.ReadLine();
string birthday = DateTime.Parse(b);
kirushan
  • 508
  • 4
  • 20