System.Text.Encoder.GetBytes C# (CSharp) Метод

GetBytes() приватный Метод

private GetBytes ( char chars, int charCount, byte bytes, int byteCount, bool flush ) : int
chars char
charCount int
bytes byte
byteCount int
flush bool
Результат int
        public virtual unsafe int GetBytes(char* chars, int charCount,
                                              byte* bytes, int byteCount, bool flush)
        {
            // Validate input parameters
            if (bytes == null || chars == null)
                throw new ArgumentNullException(bytes == null ? "bytes" : "chars",
                    Environment.GetResourceString("ArgumentNull_Array"));

            if (charCount < 0 || byteCount < 0)
                throw new ArgumentOutOfRangeException((charCount<0 ? "charCount" : "byteCount"),
                    Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));

            // Get the char array to convert
            char[] arrChar = new char[charCount];

            int index;
            for (index = 0; index < charCount; index++)
                arrChar[index] = chars[index];

            // Get the byte array to fill
            byte[] arrByte = new byte[byteCount];

            // Do the work
            int result = GetBytes(arrChar, 0, charCount, arrByte, 0, flush);

            // The only way this could fail is a bug in GetBytes
            BCLDebug.Assert(result <= byteCount, "Returned more bytes than we have space for");

            // Copy the byte array
            // WARNING: We MUST make sure that we don't copy too many bytes.  We can't
            // rely on result because it could be a 3rd party implimentation.  We need
            // to make sure we never copy more than byteCount bytes no matter the value
            // of result
            if (result < byteCount)
                byteCount = result;

            // Don't copy too many bytes!
            for (index = 0; index < byteCount; index++)
                bytes[index] = arrByte[index];

            return byteCount;
        }

Same methods

Encoder::GetBytes ( char chars, int charIndex, int charCount, byte bytes, int byteIndex, bool flush ) : int

Usage Example

Пример #1
0
 internal static string GetMd5Sum(string str)
 {
     System.Text.Encoder encoder = Encoding.Unicode.GetEncoder();
     byte[] numArray             = new byte[str.Length * 2];
     encoder.GetBytes(str.ToCharArray(), 0, str.Length, numArray, 0, true);
     return(GetMd5Sum(numArray));
 }
All Usage Examples Of System.Text.Encoder::GetBytes