Microsoft.Protocols.TestSuites.Common.Common.IsUtf16LEString C# (CSharp) Method

IsUtf16LEString() public static method

Check whether a byte array is a valid utf16 encoding or not
public static IsUtf16LEString ( byte bytes ) : bool
bytes byte The byte array to be checked
return bool
        public static bool IsUtf16LEString(byte[] bytes)
        {
            if (bytes == null)
            {
                return false;
            }

            int len = bytes.Length;
            if (len % 2 != 0)
            {
                return false;
            }

            for (int i = 1; i < len; i += 2)
            {
                if (bytes[i] != '\0')
                {
                    return false;
                }
            }

            if (bytes[len - 2] == '\0' && bytes[len - 1] == '\0')
            {
                return true;
            }

            return false;
        }
Common