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

GetCharCount() public abstract method

public abstract GetCharCount ( byte bytes, int index, int count ) : int
bytes byte
index int
count int
return int
        public abstract int GetCharCount(byte[] bytes, int index, int count);

Same methods

Decoder::GetCharCount ( byte bytes, int count, bool flush ) : 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