[英]how to convert System.Byte[] in System.IO.Stream?
I can't convert byte to stream. 我无法将字节转换为流。 Is there an easy way to do that? 有一个简单的方法吗?
Stream stream;
stream = (Stream) vByte; //something is going wrong in this part.
//vByte is a byte variable
You cannot use cast expressions to convert something to a different type. 您不能使用强制转换表达式将某些内容转换为其他类型。
Instead, you can create a MemoryStream
around the array. 相反,您可以在数组周围创建一个MemoryStream
。
In general, the cast operator changes the compile-time type of an object to a different type, provided that it actually is an instance of that type at runtime. 通常,强制转换操作符将对象的编译时类型更改为其他类型,前提是它在运行时实际上是该类型的实例。
For a detailed explanation, see this blog post . 有关详细说明,请参阅此博客文章 。
您需要使用byte[]
实例化MemoryStream
对象:
MemoryStream stream = new MemoryStream(vByte);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.