How to Convert Byte[] to stream in C# ?


This content was proof-read by Grammarly. You can Try Grammary for FREE

Below is a sample code snippet demonstrating the conversion of the byte array to stream in C#.

How to Convert Byte[] to stream in C# ?

using System;
using System.IO;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            byte[] byteArrayData = new byte[10];
            var result = ConvertByteArrayToMemoryStream(byteArrayData);
            Console.ReadLine();
        }
        // Method to convert a byte array to stream in C#
        public static MemoryStream ConvertByteArrayToMemoryStream(byte[] byteArrayData)
        {
            MemoryStream memstream = new MemoryStream();
            memstream.Write(byteArrayData, 0, byteArrayData.Length);
            return memstream;
        }
    }
    
}
%d bloggers like this: