System.Text.Decoder.GetCharCount C# (CSharp) Method

GetCharCount() private method

private GetCharCount ( byte bytes, int count, bool flush ) : int
bytes byte
count int
flush bool
return int
        public virtual unsafe int GetCharCount(byte* bytes, int count, bool flush)
        {
            // Validate input parameters
            if (bytes == null)
                throw new ArgumentNullException("bytes",
                      Environment.GetResourceString("ArgumentNull_Array"));

            if (count < 0)
                throw new ArgumentOutOfRangeException("count",
                      Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));

            byte[] arrbyte = new byte[count];
            int index;

            for (index = 0; index < count; index++)
                arrbyte[index] = bytes[index];

            return GetCharCount(arrbyte, 0, count);
        }

Same methods

Decoder::GetCharCount ( byte bytes, int index, int count ) : int
Decoder::GetCharCount ( byte bytes, int index, int count, bool flush ) : int

Usage Example

    public static Highscore Load(Stream fs, System.Text.Decoder decoder)
    {
        const int length = 4;

        byte[] data = new byte[length];
        char[] chars;
        string name;

        fs.Read(data, 0, length);
        var bytesCount = System.BitConverter.ToInt32(data, 0);

        if (bytesCount > 0 && bytesCount < 100000)
        {
            data = new byte[bytesCount];
            fs.Read(data, 0, bytesCount);
            chars = new char[decoder.GetCharCount(data, 0, bytesCount)];
            decoder.GetChars(data, 0, bytesCount, chars, 0, true);
            name = new string(chars);
        }
        else
        {
            name = "highscore";
        }
        //
        bytesCount = 9;
        data       = new byte[bytesCount];
        fs.Read(data, 0, bytesCount);
        return(new Highscore(System.BitConverter.ToInt32(data, 0), name, System.BitConverter.ToUInt32(data, 4), (GameEndingType)data[8]));
    }
All Usage Examples Of System.Text.Decoder::GetCharCount