Methods 什么';It’一次写一个字符是比较容易的

Methods 什么';It’一次写一个字符是比较容易的,methods,char,Methods,Char,我必须为我所做的每一行输入相同的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);

我必须为我所做的每一行输入相同的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);
            }

您必须定义自己的方法:

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);
}