Converting Between Strings, Byte Arrays, and MemoryStream in C#
Consider a string variable str, a MemoryStream instance ms, and a byte array bt. Below are common conversion patterns among these types in C#.
1. String to Byte Array
byte[] bt = System.Text.Encoding.Default.GetBytes("example");
byte[] bt = Convert.FromBase64String("base64EncodedString");
Different encodings can be used exp ...
Posted on Sat, 07 Nov 2026 16:33:41 +0000 by mazman13