ToBase64CharArray Method

Convert.ToBase64CharArray Method

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

Converts a subset of an 8-bit unsigned integer array to an equivalent subset of a Unicode character array encoded with base 64 digits. Parameters specify the subsets as offsets in the input and output arrays, and the number of elements in the input array to convert.

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)

public static int ToBase64CharArray(
	byte[] inArray,
	int offsetIn,
	int length,
	char[] outArray,
	int offsetOut


Type: System.Byte []
An input array of 8-bit unsigned integers.
Type: System.Int32
A position within inArray.
Type: System.Int32
The number of elements of inArray to convert.
Type: System.Char []
An output array of Unicode characters.
Type: System.Int32
A position within outArray.

Return Value

Type: System.Int32
A 32-bit signed integer containing the number of bytes in outArray.


inArray or outArray is null.


offsetIn, offsetOut, or length is negative.


offsetIn plus length is greater than the length of inArray.


offsetOut plus the number of elements to return is greater than the length of outArray.

The subset of length elements of inArray starting at position offsetIn, are taken as a numeric value and converted to a subset of elements in outArray starting at position offsetOut. The return value indicates the number of converted elements in outArray. The subset of outArray consists of base 64 digits.

The base 64 digits in ascending order from zero are the uppercase characters 'A' to 'Z', the lowercase characters 'a' to 'z', the numerals '0' to '9', and the symbols '+' and '/'. The valueless character, '=', is used for trailing padding.

The offset and length parameters are 32-bit signed numbers. The offsetIn and offsetOut parameters are zero-based array positions.

The following example demonstrates using the ToBase64CharArray method to convert a string to a UUEncoded character array and then convert it back to the original string.

byte[] bytes;
string originalString = "The contents of the original string form a sentence.";
outputBlock.Text += String.Format("The original string:\n   {0}\n", 

// Convert the string to a byte array.
UnicodeEncoding encoder = new UnicodeEncoding();
bytes = encoder.GetBytes(originalString);

// Convert the byte array to a base 64 encoded Char array.
char[] encodedChars = new char[1023]; 
int nChars;                        // Length of character array.
nChars = Convert.ToBase64CharArray(bytes, 0, bytes.Length, 
                                   encodedChars, 0);
// Display the encoded characters.
string encodedString = new string(encodedChars); 
outputBlock.Text += String.Format("The UUEncoded string:\n   {0}\n", 
                                  encodedString.Substring(0, nChars)); 

// Convert UUEncoded Char array to a byte array.
bytes = Convert.FromBase64CharArray(encodedChars, 0, nChars);

// Convert byte array back to the original string.
originalString = encoder.GetString(bytes, 0, bytes.Length); 
outputBlock.Text += String.Format("The original string restored:\n   {0}\n",
// The example displays the following output;
//       The original string:
//          The contents of the original string form a sentence.
//       The UUEncoded string:
//       The original string restored:
//          The contents of the original string form a sentence.

Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

© 2017 Microsoft