Converts the byte array to a unicode string - CSharp System

CSharp examples for System:Byte Array

Description

Converts the byte array to a unicode string

Demo Code


using System;/* ww w .  ja va  2s. c  o  m*/

public class Main{
        /// <summary>
        /// Converts the byte array to a unicode string
        /// </summary>
        /// <param name="bytes">the bytes to convert</param>
        /// <returns>A string</returns>
        public static string ToUnicodeString(this byte[] bytes)
        {
            Check.NotNull(bytes);

            var chars = new char[bytes.Length / sizeof(char)];
            Buffer.BlockCopy(bytes, 0, chars, 0, bytes.Length);
            return new string(chars);
        }
}

Related Tutorials