6

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
  • 65,263
  • 14
  • 100
  • 169

2 Answers2

7

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

    MemoryStream stream = new MemoryStream(vByte);
Evan L
  • 3,685
  • 1
  • 21
  • 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
  • 837,282
  • 173
  • 1,862
  • 1,933