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

GetByteCount() private method

private GetByteCount ( char chars, int count ) : int
chars char
count int
return int
        public unsafe override int GetByteCount(char* chars, int count)
        {
            throw null;
        }

Same methods

UTF8Encoding::GetByteCount ( char chars, int index, int count ) : int
UTF8Encoding::GetByteCount ( string chars ) : int

Usage Example

示例#1
0
        private void SimpleTestInstance(string testString, int port)
        {
            // Open a socket to the server
            TcpClient client = new TcpClient("localhost", port);
            Socket    socket = client.Client;

            // This is the string we expect to get back
            String expectedString = "Welcome!\r\n" + testString.ToUpper();

            // Convert the string into an array of bytes and send them all out.
            // Note the use of the synchronous Send here.  We can use it because
            // we don't care if the testing thread is blocked for a while.
            byte[] outgoingBuffer = encoding.GetBytes(testString);
            socket.Send(outgoingBuffer);

            // Read bytes from the socket until we have the number we expect.
            // We are using a blocking synchronous Receive here.
            byte[] incomingBuffer = new byte[encoding.GetByteCount(expectedString)];
            int    index          = 0;

            while (index < incomingBuffer.Length)
            {
                index += socket.Receive(incomingBuffer, index, incomingBuffer.Length - index, 0);
            }

            // Convert the buffer into a string and make sure it is what was expected
            String result = encoding.GetString(incomingBuffer);

            Assert.AreEqual(expectedString, result);
        }
All Usage Examples Of System.Text.UTF8Encoding::GetByteCount