从 String 到 TextReader 的扩展方法...如何关闭流?
是否可以创建与此类似的扩展方法?完成后我应该如何处理 Closing()
流?
public static TextReader ToTextReader(this string XML)
{
StringReader sr = new StringReader(XML);
return sr;
}
Is it possible to create an extension method similar to this? How should I handle Closing()
the stream when finished?
public static TextReader ToTextReader(this string XML)
{
StringReader sr = new StringReader(XML);
return sr;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你不需要;当调用代码关闭
TextReader
(理应如此)时,Stream
也会自动关闭。无需单独关闭这两个对象。You don't need to; when the calling code closes the
TextReader
(as it should), theStream
is automatically closed as well. There's no need to close both objects individually.你不应该。调用者有责任获取
TextReader
对象和相应的Stream
You shouldn't. It's the responsibility of the caller to dipsose of the
TextReader
object and the correspondingStream