Stream&和Stream之间的区别是什么?文件流? [英] What's the difference between Stream & File Stream?

查看:109
本文介绍了Stream&和Stream之间的区别是什么?文件流?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

流和文件流的实际区别是什么。我在下面提到两个实例,请解释下面两行的区别。两者都做同样的工作,但我想了解实际的差异?



//流s =新的FileStream(文件名,FileMode.Create);



// FileStream fs = File.Create(filename);

解决方案

查看文档:



流: https: //msdn.microsoft.com/en-us/library/system.io.stream(v=vs.110).aspx [ ^ ]



FileStream: https://msdn.microsoft。 com / en-us / library / system.io.filestream(v = vs.110).aspx [ ^ ]



FileStream很清楚更具体的files和Stream是FileStream的基类。


这是一个错误的,完全错误的问题,几乎所有关于差异的问题。在这种特殊情况下,这与询问企鹅和鸟有什么区别?是一样的。 Penguin是一只鸟, FileStream 是一个 Stream

https://msdn.microsoft.com/en-us/library/system .io.filestream%28v = vs.110%29.aspx [ ^ ]。



参见: https://msdn.microsoft.com/en-us/library/d62kzs03%28v=vs。 110%29.aspx [ ^ ]。



你真的需要学习OOP的基础知识。



特别是,您需要了解编译时类型 vs 运行时类型。在第一行中,构造函数返回 FileStream 的实例(与同一时间的任何构造函数一样),但是将它抽象为编译时类型。尽管如此,变量 s 的运行时类型仍然是 FileStream 。请参阅: https://msdn.microsoft.com/en-us /library/47ek66wy%28v=vs.110%29.aspx [ ^ ]。



等等......请注意,我们只讨论一些先决条件OOP,但真正的OOP在这些类型中起着重要作用;所以你需要先学习所有这些先决条件(封装,继承等),然后才能真正做任何编程。



-SA

What's the actual difference in stream and filestream. i mention two instances below please explain what's the difference in below two lines. both are doing same work but i want to understand actual difference?

// Stream s = new FileStream(filename, FileMode.Create);

// FileStream fs = File.Create(filename);

解决方案

See the documentation:

Stream: https://msdn.microsoft.com/en-us/library/system.io.stream(v=vs.110).aspx[^]

FileStream: https://msdn.microsoft.com/en-us/library/system.io.filestream(v=vs.110).aspx[^]

FileStream is clearly more specific for files and Stream is the base class for FileStream.


This is a wrong, totally wrong question, as nearly all questions about "difference". In this particular case, this is the same as asking "what is the difference between penguin and bird?" Penguin is a bird, and FileStream is a Stream:
https://msdn.microsoft.com/en-us/library/system.io.filestream%28v=vs.110%29.aspx[^].

See also: https://msdn.microsoft.com/en-us/library/d62kzs03%28v=vs.110%29.aspx[^].

You really need to learn the basics of OOP.

In particular, you need to understand the compile-time types vs runtime types. In your first line, the constructor returns an instance of FileStream (as any constructor of the same time would do), but you abstract it up to the compile-time type Stream. Nevertheless, runtime type of the variable s is still FileStream. Please see: https://msdn.microsoft.com/en-us/library/47ek66wy%28v=vs.110%29.aspx[^].

And so on… Mind you, we are only discussing some prerequisites to OOP, but the "real" OOP plays fundamental role in these types; so you need to learn all those prerequisites (encapsulation, inheritance, and so on) really well, before you can really do any programming.

—SA


这篇关于Stream&和Stream之间的区别是什么?文件流?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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