EndOfStream为BinaryReader [英] EndOfStream for BinaryReader

查看:172
本文介绍了EndOfStream为BinaryReader的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

BinaryReader没有EndOfStream属性。 ?是否可以安全使用下面的代码来检查是否到达流的末尾

BinaryReader does not have EndOfStream property. Is it safe to use following code to check if end of stream is reached?

reader.BaseStream.Length> reader.BaseStream.Position

推荐答案

这要看情况。有没有实现的长度或位置属性的各种流类型,你会得到一个NotSupportedException异常。的NetworkStream为例。当然,如果你使用这种流,那么你真的要了前面多久调用BinaryReader.Read()方法知道的。所以,是的,它的罚款。

It depends. There are various stream types that do not implement the Length or Position property, you'd get a NotSupportedException. NetworkStream for example. Of course, if you'd use such a stream then you really do have to know up front how often to call the BinaryReader.Read() method. So, yes, it's fine.

这篇关于EndOfStream为BinaryReader的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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