byte to memorystream c# code example
Example 1: c# string to memorystream
public static MemoryStream GenerateStreamFromString(string value)
{
return new MemoryStream(Encoding.UTF8.GetBytes(value ?? ""));
}
Example 2: c# byte array to stream
Stream stream = new MemoryStream(byteArray);
Example 3: c# memorystream to byte array
byte[] byteArray = memoryStream.ToArray()
Example 4: c# write byte[] to stream
static void Write(Stream s, Byte[] bytes)
{
using (var writer = new BinaryWriter(s))
{
writer.Write(bytes);
}
}