Stream.Seek(0,SeekOrigin.Begin)或位置= 0 [英] Stream.Seek(0, SeekOrigin.Begin) or Position = 0

查看:1572
本文介绍了Stream.Seek(0,SeekOrigin.Begin)或位置= 0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当你需要一个流重置为开始(例如的MemoryStream )是它的最佳实践使用

When you need to reset a stream to beginning (e.g. MemoryStream) is it best practice to use

stream.Seek(0, SeekOrigin.Begin);

stream.Position = 0;

我已经看到了这两个做工精细,但想知道如果一个比另一个更正确的?

I've seen both work fine, but wondered if one was more correct than the other?

推荐答案

使用位置。两者都提供了方便,所以你可以选择一个适合你的code的风格和可读性。访问职位要求的流是可查找所以他们安全地互换。

Use Position when setting an absolute position and Seek when setting a relative position. Both are provided for convenience so you can choose one that fits the style and readability of your code. Accessing Position requires the stream be seekable so they're safely interchangeable.

这篇关于Stream.Seek(0,SeekOrigin.Begin)或位置= 0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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