Click here to Skip to main content
15,891,248 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Everyone!

I Start C# Few Days Ago But i still Got One Problem In Input From the User.When I Say User To Enter Data Then It Take Input in Next Line not In One line

But i want user give him Input In One LIne.

For Example
I say Enter Your Name://I Want input Field In There Not in Below Line/New Line.

Code

C#
string Name;
Console.WriteLine("Enter Your Name:");
Name=Conver.ToSting(Console.ReadLine());
Console.ReadLine();
Posted
Updated 12-Aug-14 10:50am
v2
Comments
PIEBALDconsult 12-Aug-14 11:37am    
"Conver.ToSting(Console.ReadLine());"

It is a string already; you don't need to convert it.
In fact, please avoid using Convert entirely; most beginners use Convert because they don't understand what they're doing.

Don't use Console.WriteLine... it writes the text and appends a new line to the end. Use Console.Write to leave the cursor at the end of the line.

Note too that ReadLine will read the text entered up to the user hitting 'enter'. There is also a Console.Read function that will return each character entered. You might use that if you present a menu or something and want to get the user's choice or if you ask them to confirm something and don't want them to have to hit enter.

Good luck!
 
Share this answer
 
H, Please try out the following solution.
C#
Console.WriteLine("Enter a text");
var mytext = Console.ReadLine();
Console.WriteLine(mytext.ToString());
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900