[英]How do I make my console window stop making me type enter in Visual Studio?
I have a simple application to practice C# but my console window makes me type enter instead of showing the whole result at once and I don't think that there is anything wrong with the code. 我有一个简单的应用程序来练习C#,但我的控制台窗口让我输入enter而不是一次显示整个结果,我不认为代码有任何问题。 I have pasted my code here anyways. 无论如何我在这里粘贴了我的代码。 I just don't want to have to type enter every time I want to see something in the console window. 我只是不想每次想要在控制台窗口中看到某些内容时输入enter。 How do I change this? 我该如何改变?
namespace CallingMethods
{
class Program
{
static void Main(string[] args)
{
NameGame("John", "Smith");
int myNumber = NumberGame(1234);
Console.WriteLine(myNumber); Console.ReadLine();
}
public static void NameGame(string firstName, string lastName)
{
char[] firstNameArray = firstName.ToCharArray();
Array.Reverse(firstNameArray);
char[] lastNameArray = lastName.ToCharArray();
Array.Reverse(lastNameArray);
string result = " ";
foreach (char item in firstNameArray)
{
result+=item;
}
result += " ";
foreach (char item in lastNameArray)
{
result += item;
}
Console.WriteLine(result); Console.ReadLine();
}
private static int NumberGame(int v)
{
return (v*2) * 100;
}
}
} }
You have Console.ReadLine();
你有Console.ReadLine();
at the end of NameGame()
and the result is printed after this call. 在NameGame()
的末尾,结果在此调用后打印。 Due to this you need to enter a line before it gives you result. 因此,您需要在给出结果之前输入一行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.