gpt4 book ai didi

c# - 为什么我的 hello world with streams 不显示任何内容?

转载 作者:太空狗 更新时间:2023-10-30 00:21:15 25 4
gpt4 key购买 nike

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

最佳答案

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

关于c# - 为什么我的 hello world with streams 不显示任何内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6408510/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com