Reputation: 21
I have something like this:
Console.WriteLine("Y =");
Y = Convert.ToInt32(Console.ReadLine());
and it displays like this
Y=
//and here i have to input my value
I want to put my value on the same row
Y= //here to input my value
Any tips?
Upvotes: 4
Views: 779
Reputation: 11741
try Console.Write("Y =");
instead of
Console.WriteLine("Y = ");
because writeline provides new line while only Write does not.
As documented here http://social.msdn.microsoft.com/Forums/vstudio/en-US/5ff3931a-8113-4f8c-a1dd-801d8e6db0e5/whats-the-difference-between-write-and-writeline :-
Write procedure writes a text and places the caret to after the last character in the text.
Console.Write("Thank you") -
Output: Thank you)
WriteLine rocedure writes a text and places the caret to the next line(like pressing enter in MS WORD)
Console.WriteLine("Thank you") -
Output: Thank you
| -> caret is placed here.
)
Environment.NewLine forces the caret to to a new line.(like \n in programming languages)
Console.Write("Thank" + Environment.NewLine + "you") -
Output: Thank
you)
Upvotes: 2
Reputation: 460238
Then you neeed
Console.Write("Y = ");
instead of
Console.WriteLine("Y = ");
Upvotes: 6