Convert Byte Array to String in C#

Converting a byte array to a string in C# is easy. In fact, it can be done in a single line. Below is an example that converts a string into a byte array. In the example that follows, we will then convert that byte array back to a string, effectively showing you how to do the conversion both ways.

Now if we want to do the conversion in the other direction, that is from a byte array to a string, then this can simply be done as follows.

string converted = Encoding.UTF8.GetString(buffer, 0, buffer.Length);

As you can see, C# makes it very easy to convert strings to and from byte arrays. I hope this helped you. Thank you for reading!

Bo Andersen

About the Author

I am a back-end web developer with a passion for open source technologies. I have been a PHP developer for many years, and also have experience with Java and Spring Framework. I currently work full time as a lead developer. Apart from that, I also spend time on making online courses, so be sure to check those out!