队列<字节>与流字节>
C# 中的队列和流有区别吗?
Is there an difference between a Queue and a Stream in C#?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
C# 中的队列和流有区别吗?
Is there an difference between a Queue and a Stream in C#?
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(3)
问题应该是:除了都提供某种检索字节的接口之外,它们还有什么共同点吗?
队列
Queue
就是一个 FIFO 字节队列,主要功能是一次将单个字节值入队或出队 - 没有随机访问。您通常使用队列作为数据结构或算法的一部分(即想到树中的广度优先搜索)。队列中的所有数据都存储在内存中。另一方面,流是字节流的抽象表示,通常从文件、内存、网络或其他源获取 - 总是有一个底层源或目标。该源不必位于内存中,即网络中或文件流将允许您读取或写入文件或网络 - 因此流是从 A 到 B 获取字节的主要方式。
The question should be: do they even have anything in common besides both offering some sort of interface to retrieve bytes from?
A queue
Queue<byte>
is just that, a FIFO queue of bytes, main functionality is to enqueue or dequeue a single byte value at a time - there is no random access. You usually use a queue as part of a data structure or algorithm (i.e. breadth first search in a tree comes to mind). All data in a queue is stored in memory.A stream on the other hand is an abstract representation of a byte stream usually obtained from a file, memory, network or other source - there is always an underlying source or target.This source doesn't have to be in memory, i.e. a network or file stream will allow you to read from or write to a file or network - so a stream is the main way to get bytes from A to B.
队列必须存储字节,而流则不需要。差别很大。
A queue has to stores bytes, a stream doesn't. Big difference.
我根本不是 C#(甚至 .NET)人员,希望有人能提供更详细的答案,但是..
我认为
Queue
和Stream
很清楚是完全不同的。我理解您为什么会问,但即使快速浏览一下 API 也会发现很多差异。http://msdn.microsoft.com/en-us/library /system.io.stream.aspx
http://msdn.microsoft.com/en-us/library /system.collections.queue.aspx
这些差异中最重要的是队列是 Collections 包的一部分,而
Stream
是IO
的一部分编辑 - 类型化队列是可能更适用,如其他海报所示
http://msdn.microsoft.com/en-us/library/7977ey2c.aspx
Im not a C# (or even .NET) guy at all, and hopefully someone will provide a more detailed answer, but..
I think its pretty clear that
Queue
andStream
are quite different. I understandwhy you'd ask, but even a quick peek at the API shows a lot of differences.http://msdn.microsoft.com/en-us/library/system.io.stream.aspx
http://msdn.microsoft.com/en-us/library/system.collections.queue.aspx
Foremost among these differences is that a Queue is part of Collections package and
Stream
is part ofIO
EDIT - typed Queue is probably more applicable, as shown with other poster
http://msdn.microsoft.com/en-us/library/7977ey2c.aspx