在C#控制台应用程序中一次写一个字符? [英] Writing one character at a time in a C# Console Application?

查看:63
本文介绍了在C#控制台应用程序中一次写一个字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不确定如何解释这个问题...

I'm not sure how to explain this...

基本上,我希望能够像以前的旧RPG一样在控制台窗口中编写文本行写他们的对话,一次一个角色。宠物小精灵神秘地牢(包含剧透)的示例如下: http://www.youtube。 com / watch?v = i29juf2e92c

Basically I want to be able to write lines of text in a console window like old RPGs used to write their dialogue, one character at a time. An example here from the game Pokemon Mystery Dungeon(Contains spoilers btw): http://www.youtube.com/watch?v=i29juf2e92c

基本类似于对话框的显示方式。

Basically like how the dialogue is displayed.

编辑:还应该提一下,我将从文件中读取文本,我想一次在一个文件中写入文本。

Should also mention, I'm going to be reading the text from a file, and I'd like to write the text in that file one character at a time.

推荐答案

您可以只使用 Console.Write 一次打印一个字符而没有 WriteLine 提供的换行符,然后调用 Thread.Sleep 可以在字符之间短暂地暂停。例如:

You can just use Console.Write to print a single character at a time without the line break that WriteLine would provide, and call Thread.Sleep to pause briefly between characters. For example:

using System;
using System.Threading;

class Program
{
    static void Main(string[] args)
    {
        string text = "This will be printed one character at a time";
        foreach (char c in text)
        {
            Console.Write(c);
            Thread.Sleep(50);
        }
    }
}

这篇关于在C#控制台应用程序中一次写一个字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆