简体   繁体   中英

How can I make the sentence print out one letter at a time?

I am trying to make this sentence print out one letter at a time, but I am unsure of how to do it. I did try looking at Thread.Sleep, but it didn't really work out for me.

            string Streamer = "Who is your favorite streamer?";

            char[] charSentence3 = Streamer.ToCharArray();
            Array.Reverse(charSentence3);

            foreach(char Streamerchar in charSentence3)
            {
                Console.WriteLine(Streamerchar);
            }
            Console.ReadLine();

Basically, I just want to make the sentence "Who is your favorite streamer" print out one letter at a time.

You're on the right track...

        string streamer = "Who is your favorite streamer?";
        
        foreach(char streamerchar in streamer)
        {
            Thread.Sleep(500);
            Console.Write(streamerchar);
        }
        Console.ReadLine();

Strings can be enumerated to get their chars

You need to thread.Sleep inside the loop to make it look delayed..

..but that's about it!

        string Streamer = "Who is your favorite streamer?";

        foreach  (char c in Streamer)
        {
            Thread.Sleep(100);
            Console.WriteLine(c);
        }
        Console.ReadLine();

This is what you looking for

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM