我必须继续为每个Writeline输入相同的4行程序,我可以制作一种方法还是一种更简单的方法?
static void Main(string[] args)
{
string text = "You wake up, you raise your head off the floor";
foreach (char c in text)
{
Console.Write(c);
Thread.Sleep(50);
}
Thread.Sleep(200);
Console.WriteLine("\nPress Enter to continue");
Console.ReadLine();
text = "You gather your senses, and you...";
foreach (char c in text)
{
Console.Write(c);
Thread.Sleep(50);
}
答案 0 :(得分:1)
您必须定义自己的方法:
static void WriteCharByChar(string text)
{
foreach (char c in text)
{
Console.Write(c);
Thread.Sleep(50);
}
}
然后只需称呼它:
static void Main(string[] args)
{
string text = "You wake up, you raise your head off the floor";
WriteCharByChar(text);
Thread.Sleep(200);
Console.WriteLine("\nPress Enter to continue");
Console.ReadLine();
text = "You gather your senses, and you...";
WriteCharByChar(text);
}