Reading three inputs from the user using Console.ReadLine()

Abner_CV picture Abner_CV · Feb 7, 2014 · Viewed 9.4k times · Source

Is this the correct way to do it, since I'm new to C#

Console.WriteLine("please enter m,y,n: \n");
double month, year, numberOfMonths = Convert.ToDouble(Console.ReadLine());

Answer

Ehsan picture Ehsan · Feb 7, 2014

You can do it by asking user to enter the values split-ed by some delimiter like space, semi colon etc. And then split the value and parse accordingly. for example

string input = Console.ReadLine();
string[] split = input.Split(',');
double month = Double.Parse(split[0]);
double year = Double.Parse(split[1]);
double numberofmonth = Double.Parse(split[2]);

Ofcourse the above code is not the most elegant/efficient/error free code. But, it is just written to get the idea across.