Tuesday, June 17, 2025

How to convert bytes to string and string to bytes in c#

 


        string author = "Mahesh Chand";

        // Convert a C# string to a byte array

        byte[] bytes = Encoding.ASCII.GetBytes(author);

        foreach (byte b in bytes)

        {

            Response.Write(b );

            Response.Write(Environment.NewLine);                       

        }


bytes to string

string myString = Encoding.ASCII.GetString(bytes);

Response.Write(str);

No comments:

Post a Comment