How can I input multiple integers or strings in one line?
For example, int p would take values:
1 2 3 4 5 6
but now I know the answer to my own question i.e:
var p= Console.ReadLine().split(' ');
How can I input multiple integers or strings in one line?
For example, int p would take values:
1 2 3 4 5 6
but now I know the answer to my own question i.e:
var p= Console.ReadLine().split(' ');
You can read line with numbers or srings separated with spaces (or other symbols). Then you can split the line into parts and parse values.
var line = Console.ReadLine();
var data = line.Split(' ');
var i1 = int.Parse(data[0]); //first integer
var i2 = int.Parse(data[1]); //second integer
You will need to accept the single line and then split them up based on how you want the inputs separate. For example, if you make the users type in:
1,2,3
then you need to split around the comma and convert the input to numbers:
foreach (var sn in inp.Split(',')) {
var n = Convert.ToInt32(sn);
// work with n
}