4

我正在尝试将二进制数据流式传输到 .NET 中的标准输出。但是,您只能使用 Console 类编写 char 。我想将它与重定向一起使用。有没有办法做到这一点?

4

1 回答 1

6

您可以使用 访问输出流Console.OpenStandardOutput

    static void Main(string[] args) {
        MemoryStream data = new MemoryStream(Encoding.UTF8.GetBytes("Some data"));
        using (Stream console = Console.OpenStandardOutput()) {
            data.CopyTo(console);
        }
    }
于 2008-09-21T16:52:28.070 回答