System.Text.Encoding.GetByteCount C# (CSharp) Method

GetByteCount() public method

public GetByteCount ( String s ) : int
s String
return int
        public virtual int GetByteCount(String s)
        {
            if (s==null)
                throw new ArgumentNullException("s");

            char[] chars = s.ToCharArray();
            return GetByteCount(chars, 0, chars.Length);

        }

Same methods

Encoding::GetByteCount ( char chars ) : int
Encoding::GetByteCount ( char chars, int count ) : int
Encoding::GetByteCount ( char chars, int count, EncoderNLS encoder ) : int
Encoding::GetByteCount ( char chars, int index, int count ) : int

Usage Example

示例#1
0
        public void WriteToStream(Stream outputStream, Encoding encoding)
        {
            outputStream.WriteByte((Byte)'P');

            // message length =
            // Int32 self
            // name of prepared statement + 1 null string terminator +
            // query string + 1 null string terminator
            // + Int16
            // + Int32 * number of parameters.
            Int32 messageLength = 4 + encoding.GetByteCount(_prepareName) + 1 + encoding.GetByteCount(_queryString) + 1 + 2 + (_parameterIDs.Length * 4);
            //Int32 messageLength = 4 + _prepareName.Length + 1 + _queryString.Length + 1 + 2 + (_parameterIDs.Length * 4);

            PGUtil.WriteInt32(outputStream, messageLength);
            PGUtil.WriteString(_prepareName, outputStream, encoding);
            PGUtil.WriteString(_queryString, outputStream, encoding);
            PGUtil.WriteInt16(outputStream, (Int16)_parameterIDs.Length);


            for(Int32 i = 0; i < _parameterIDs.Length; i++)
                PGUtil.WriteInt32(outputStream, _parameterIDs[i]);




        }
All Usage Examples Of System.Text.Encoding::GetByteCount