BitConverter::ToString Method (array<Byte>^)
Converts the numeric value of each element of a specified array of bytes to its equivalent hexadecimal string representation.
Assembly: mscorlib (in mscorlib.dll)
Parameters
- value
-
Type:
array<System::Byte>^
An array of bytes.
Return Value
Type: System::String^A string of hexadecimal pairs separated by hyphens, where each pair represents the corresponding element in value; for example, "7F-2C-4A-00".
| Exception | Condition |
|---|---|
| ArgumentNullException | value is null. |
All the elements of value are converted. The order of hexadecimal strings returned by the ToString method depends on whether the computer architecture is little-endian or big-endian.
The following code example converts Byte arrays to String objects with the ToString method.
// Example of the BitConverter::ToString( unsigned char[ ] ) method. using namespace System; // Display a byte array with a name. void WriteByteArray( array<unsigned char>^bytes, String^ name ) { String^ underLine = "--------------------------------"; Console::WriteLine( name ); Console::WriteLine( underLine->Substring( 0, Math::Min( name->Length, underLine->Length ) ) ); Console::WriteLine( BitConverter::ToString( bytes ) ); Console::WriteLine(); } int main() { array<unsigned char>^arrayOne = {0,1,2,4,8,16,32,64,128,255}; array<unsigned char>^arrayTwo = {32,0,0,42,0,65,0,125,0,197,0,168,3,41,4,172,32}; array<unsigned char>^arrayThree = {15,0,0,128,16,39,240,216,241,255,127}; array<unsigned char>^arrayFour = {15,0,0,0,0,16,0,255,3,0,0,202,154,59,255,255,255,255,127}; Console::WriteLine( "This example of the " "BitConverter::ToString( unsigned char[ ] ) \n" "method generates the following output.\n" ); WriteByteArray( arrayOne, "arrayOne" ); WriteByteArray( arrayTwo, "arrayTwo" ); WriteByteArray( arrayThree, "arrayThree" ); WriteByteArray( arrayFour, "arrayFour" ); } /* This example of the BitConverter::ToString( unsigned char[ ] ) method generates the following output. arrayOne -------- 00-01-02-04-08-10-20-40-80-FF arrayTwo -------- 20-00-00-2A-00-41-00-7D-00-C5-00-A8-03-29-04-AC-20 arrayThree ---------- 0F-00-00-80-10-27-F0-D8-F1-FF-7F arrayFour --------- 0F-00-00-00-00-10-00-FF-03-00-00-CA-9A-3B-FF-FF-FF-FF-7F */
Available since 8
.NET Framework
Available since 1.1
Portable Class Library
Supported in: portable .NET platforms
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1