convert bites to string C# code example

Example 1: convert system.byte a string c#

string result = System.Text.Encoding.UTF8.GetString(byteArray);

Example 2: c# store byte array as string

static string BytesToString(byte[] bytes)
    {
        using (MemoryStream stream = new MemoryStream(bytes))
        {
            using (StreamReader streamReader = new StreamReader(stream))
            {
                return streamReader.ReadToEnd();
            }
        }
    }
 
    public static void Main()
    {
        byte[] bytes = Encoding.ASCII.GetBytes("ABC123");
        Console.WriteLine("Byte Array is: " + String.Join(" ", bytes));
 
        string str = BytesToString(bytes);
        Console.WriteLine("The String is: " + str);
    }