Reputation: 562
First off, this question IS NOT
System.Console.Write instead of System.Console.WriteLine
....
<Console.Write();>: <Console.ReadLine>
I think this best explains my question,
I have...
string stringone = Console.ReadLine();
string stringtwo = Console.ReadLine();
....
//what it does
<Console.ReadLine> (after enter is pressed moves to next line)
<Console.ReadLine>
//what I want
<Console.ReadLine> <Console.ReadLine>
Any alternative/solution or grounds if this is possible is greatly apreciated.
Upvotes: 3
Views: 2693
Reputation: 1255
using System;
class Test
{
static void Main()
{
//split input by spaces into array
string[] name = Console.ReadLine().Split();
Console.WriteLine("First name: " + name[0]);
Console.WriteLine("Last Name: " + name[1]);
}
}
Upvotes: 3
Reputation: 3072
Use SetCursorPosition.
using System;
class Program
{
public static void Main(string[] args)
{
string question1 = "What is your name? ";
string question2 = "How old are you? ";
// first question
Console.Write(question1);
string name = Console.ReadLine();
// second question
Console.SetCursorPosition(question1.Length + name.Length + 1, 0);
Console.Write(question2);
string age = Console.ReadLine();
// print output
Console.WriteLine("Hello {0}, your age is {1}", name, age);
Console.Write("Press any key to continue . . . ");
Console.ReadKey(true);
}
}
https://msdn.microsoft.com/en-us/library/system.console.setcursorposition(v=vs.110).aspx
Upvotes: 2
Reputation: 2975
This should do the trick:
string one = Console.ReadLine();
Console.SetCursorPosition(one.Length + 1, 0);
string two = Console.ReadLine();
Console.SetCursorPosition(one.Length + two.Length + 2, 0);
Upvotes: 1