7

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
meriton
  • 68,356
  • 14
  • 108
  • 175

2 Answers2

8

You need to instantiate a MemoryStream object with the byte[]:

    MemoryStream stream = new MemoryStream(vByte);
Evan L
  • 3,805
  • 1
  • 22
  • 31
6

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.

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964