C# UnicodeEncoding GetString(Byte[])

Description

UnicodeEncoding GetString(Byte[]) When overridden in a derived class, decodes all the bytes in the specified byte array into a string.

Syntax

UnicodeEncoding.GetString(Byte[]) has the following syntax.


public virtual string GetString(
  byte[] bytes
)

Parameters

UnicodeEncoding.GetString(Byte[]) has the following parameters.

  • bytes - The byte array containing the sequence of bytes to decode.

Returns

UnicodeEncoding.GetString(Byte[]) method returns A string that contains the results of decoding the specified sequence of bytes.

Example

The following example reads a UTF-8 encoded string from a binary file represented by a FileStream object.


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

public class Example
{
    public static void Main()
    {

        Encoding enc8 = Encoding.UTF8;
        string contents = contents = enc8.GetString(new byte[] {1 });
        Console.WriteLine(contents);
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System.Text »




ASCIIEncoding
Encoding
EncodingInfo
StringBuilder
UnicodeEncoding
UTF8Encoding