This documentation is archived and is not being maintained.

Encoding.GetBytes Method (String, Int32, Int32, Byte[], Int32)

.NET Framework 1.1

Encodes the specified range of a String into the specified range of a byte array.

[Visual Basic]
Overloads Public Overridable Function GetBytes( _
   ByVal s As String, _
   ByVal charIndex As Integer, _
   ByVal charCount As Integer, _
   ByVal bytes() As Byte, _
   ByVal byteIndex As Integer _
) As Integer
public virtual int GetBytes(
 string s,
 int charIndex,
 int charCount,
 byte[] bytes,
 int byteIndex
public: virtual int GetBytes(
 String* s,
 int charIndex,
 int charCount,
 unsigned char bytes __gc[],
 int byteIndex
public function GetBytes(
   s : String,
 charIndex : int,
 charCount : int,
 bytes : Byte[],
 byteIndex : int
) : int;


A String to encode.
The first index of s from which to encode.
The number of characters of s to encode.
The byte array to encode into.
The first index of bytes to encode into.

Return Value

The number of encoded bytes in array bytes.


Exception Type Condition
ArgumentException bytes does not contain sufficient space to store the encoded characters.
ArgumentNullException s or bytes is a null reference (Nothing in Visual Basic).
ArgumentOutOfRangeException charIndex, charCount, or byteIndex is less than zero.


charIndex and charCount do not specify a valid range in s (that is, (charIndex + charCount) is greater than the length of s).


Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework, Common Language Infrastructure (CLI) Standard

See Also

Encoding Class | Encoding Members | System.Text Namespace | Encoding.GetBytes Overload List