简体   繁体   中英

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.

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM