Renci.SshNet.Common.ASCIIEncoding.GetBytes C# (CSharp) Method

GetBytes() public method

Encodes a set of characters from the specified character array into the specified byte array.
is null.-or- is null. or or is less than zero.-or- and do not denote a valid range in .-or- is not a valid index in . does not have enough capacity from to the end of the array to accommodate the resulting bytes.
public GetBytes ( char chars, int charIndex, int charCount, byte bytes, int byteIndex ) : int
chars char The character array containing the set of characters to encode.
charIndex int The index of the first character to encode.
charCount int The number of characters to encode.
bytes byte The byte array to contain the resulting sequence of bytes.
byteIndex int The index at which to start writing the resulting sequence of bytes.
return int
        public override int GetBytes(char[] chars, int charIndex, int charCount, byte[] bytes, int byteIndex)
        {
            for (var i = 0; i < charCount && i < chars.Length; i++)
            {
                var b = (byte)chars[i + charIndex];

                if (b > 127)
                    b = (byte) _fallbackChar;

                bytes[i + byteIndex] = b;
            }
            return charCount;
        }

Usage Example

示例#1
0
 public void GetBytesTest()
 {
     ASCIIEncoding target = new ASCIIEncoding(); // TODO: Initialize to an appropriate value
     char[] chars = null; // TODO: Initialize to an appropriate value
     int charIndex = 0; // TODO: Initialize to an appropriate value
     int charCount = 0; // TODO: Initialize to an appropriate value
     byte[] bytes = null; // TODO: Initialize to an appropriate value
     int byteIndex = 0; // TODO: Initialize to an appropriate value
     int expected = 0; // TODO: Initialize to an appropriate value
     int actual;
     actual = target.GetBytes(chars, charIndex, charCount, bytes, byteIndex);
     Assert.AreEqual(expected, actual);
     Assert.Inconclusive("Verify the correctness of this test method.");
 }
All Usage Examples Of Renci.SshNet.Common.ASCIIEncoding::GetBytes