Reading two user inputs

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

+4
source share
2 answers

Something like that?

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

In this example, space limits arguments. You can use , or ; as a separator if you want.

+6
source
 Console.WriteLine("Enter values separated by space"); string input = Console.ReadLine(); string[] inputs = input.Split(' '); foreach (string inp in inputs) { Console.WriteLine(inp); } 
+2
source

All Articles