C#新行问题 [英] C# New Line Problem Issue

查看:59
本文介绍了C#新行问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!



我开始使用C#几天前但我仍然遇到用户输入的一个问题。当我说用户输入数据然后它在下一行输入不在一行中



但是我希望用户给他输入一个LIne。



例如

我说输入你的名字://我想要输入字段不在下面的行/新行。



代码



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

string Name;
Console.WriteLine("Enter Your Name:");
Name=Conver.ToSting(Console.ReadLine());
Console.ReadLine();

推荐答案

不要使用Console.WriteLine ...它会写入文本并附加到最后的新行。使用Console.Write将光标留在行尾。



另请注意,ReadLine将读取输入到用户点击'enter'的文本。还有一个Console.Read函数,它将返回输入的每个字符。你可以使用它,如果你提出一个菜单或其他东西,并希望得到用户的选择,或者你要求他们确认一些东西,并且不希望他们必须输入。



祝你好运!
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!


H,请试用以下解决方案。

H, Please try out the following solution.
Console.WriteLine("Enter a text");
var mytext = Console.ReadLine();
Console.WriteLine(mytext.ToString());


这篇关于C#新行问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆