System.Text.ISCIIEncoding.GetMaxCharCount C# (CSharp) Method

GetMaxCharCount() public method

public GetMaxCharCount ( int byteCount ) : int
byteCount int
return int
        public override int GetMaxCharCount(int byteCount)
        {
            if (byteCount < 0)
                throw new ArgumentOutOfRangeException(nameof(byteCount), SR.ArgumentOutOfRange_NeedNonNegNum);
            Contract.EndContractBlock();

            // Our MaxCharCount is the same as the byteCount.  There are a few sequences
            // where 2 (or more) bytes could become 2 chars, but that's still 1 to 1.
            // Also could have 1 in decoder if we're waiting to see if next char's a nukta.
            long charCount = ((long)byteCount + 1);

            // Some code points are undefined so we could fall back.
            if (DecoderFallback.MaxCharCount > 1)
                charCount *= DecoderFallback.MaxCharCount;

            if (charCount > 0x7fffffff)
                throw new ArgumentOutOfRangeException(nameof(byteCount), SR.ArgumentOutOfRange_GetCharCountOverflow);

            return (int)charCount;
        }