【问题标题】:Why does my hello world with streams not show anything?为什么我的带有流的 hello world 没有显示任何内容?
【发布时间】:2011-06-20 08:22:27
【问题描述】:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace CSQuick
{
    class Program
    {
        static void Main(string[] args)
        {
            using (var ff = new MemoryStream())
            using (var f = new StreamWriter(ff))
            {
                f.WriteLine("Stream hello world fail");
                f.Flush();
                using (TextReader ts = new StreamReader(ff))
                {
                    Console.WriteLine(ts.ReadToEnd());
                }
            }
        }
    }
}

【问题讨论】:

    标签: c# .net stream


    【解决方案1】:

    设置
    ff.Position = 0;
    在阅读之前,否则您将在流的末尾开始阅读。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多