Convert byte array into a string using MemoryStream in CSharp

Description

The following code shows how to convert byte array into a string using MemoryStream.

Example


/*w  w w .j a  v  a  2  s .c  om*/
using System;
using System.IO;
using System.Text;

public static class CompressionUtility
{
    public static string ConvertBytesToString(byte[] bytes)
    {
        string output = String.Empty;
        MemoryStream stream = new MemoryStream(bytes);
        stream.Position = 0;
        using (StreamReader reader = new StreamReader(stream))
        {
            output = reader.ReadToEnd();
        }
        return output;
    }
}




















Home »
  C# Tutorial »
    Data Types »




C# Data Types
Bool
Byte
Char
Decimal
Double
Float
Integer
Long
Short
String
C# Array
Array Example
Byte Array
C# Standard Data Type Format
BigInteger
Complex
Currency
DateTime
DateTimeOffset
DateTime Format Parse Convert
TimeSpan
TimeZone
Enum
Null
tuple
var