The BitConverter Class
C# provides a simple class, BitConverter
, to simplify the conversion of primitive data types to an array of bytes and vice versa.
using System;
class Program
{
static void Main()
{
// Create an array of bytes
byte[] byteArray = { 72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100 };
// Convert bytes to string
string resultString = Encoding.UTF8.GetString(byteArray);
// Display the result
Console.WriteLine("Byte to String Conversion Result: " + resultString);
}
}
Output:
Byte to String Conversion Result: Hello World
Comments (0)