Reading two inputs from the user

Sinan picture Sinan · Jun 6, 2011 · Viewed 9k times · Source

I would like to get the user enters two different values using only ONE statement of Console.ReadLine(). More specifically, instead of using two different variables declarations with two different ReadLine() method - I want to let the user enters two variables at the same time using one ReadLine() method for further processing.

Answer

Alex Aza picture Alex Aza · Jun 6, 2011

Something like this?

var line = Console.ReadLine();
var arguments = line.Split(' ');
var arg1 = arguments[0];
var arg2 = arguments[1];

In this example, space delimits the arguments. You can use , or ; as a delimiter, if you would like to.