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

Published on June 7, 2015 by abundantcode

Filed under C#

Last modified June 7, 2015

Print this page

rate 1 star rate 2 star rate 3 star rate 4 star rate 5 star
Your rating: none, Average: 0 (0 votes)

This article have been viewed 6214 times

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

Leave a Comment


x

You might be Interested in these Posts

How to Create an Empty array without defining the size in C# ?

When we create an array in C# , we tend to define the size of the array as shown below. String[] st...

How to use array Rank in C# ?

In C# , the Rank property of the array is is used to get the rank of the array. In simple terms , ra...

How to get the Number of Elements in an MultiDimensional Array in C# ?

In one of the previous articles , we demonstrated the usage of the Length property of the array in C...