如何使文本“被键入”?在控制台应用程序中? [英] How to make text be "typed out" in console application?
本文介绍了如何使文本“被键入”?在控制台应用程序中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
就像计算机在战争游戏中 一样一个>。我已经开始了,但是我不知道从这里去哪里。
Just like the way the computer does it in War Games. I've started, but I don't know where to go from here.
static void TypeLine(string line)
{
string output = null;
char[] characters = line.ToCharArray();
for (int i = 0; i < characters.Length; i++)
{
output += characters[i];
Console.Clear();
}
Console.WriteLine(output);
}
我的想法是分割要输出的字符串,添加一个字符,清除控制台,添加另一个,依此类推。我知道了,但我真的不知道如何添加,然后清除,然后再次添加。一些技巧可能很不错,如果您愿意的话,甚至可以完成代码。
My idea was to split the string you wanted it to output, add a character, clear the console, add another, and so on. I got that far, but I don't really know how to make it add, then clear, then add again. Some tips would be nice, or even completed code if you feel like it.
推荐答案
最简单的方法可能是Sleep()字符之间。像这样:
The easiest way may be to Sleep() between characters. Something like this:
static void TypeLine(string line) {
for (int i = 0; i < line.Length; i++) {
Console.Write(line[i]);
System.Threading.Thread.Sleep(150); // Sleep for 150 milliseconds
}
}
这篇关于如何使文本“被键入”?在控制台应用程序中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文