preface

No matter what language is developed, there will always be conversions between different types of data. C# is no exception, but C# has already done some of the conversion for us.

Commonly used conversion classes.

Encoding BitConverter Convert Marshal namespace static methods in System space such as int.parse ()

Two. Data conversion

1.byte[] => string

Method 1: strings str1 = System. Text. Encoding. The Default. Get string (byteArray containing); String str2 = BitConverter.ToString(ByteArray); String str3 = Convert.toBase64String (ByteArray); String str3 = Convert.toBase64String (ByteArray); String str3 = Convert.toBase64String (ByteArray); Method 4: string str4 = HttpServerUtility. UrlTokenEncode (byteArray containing);

2.string => byte[]

Method 1: byte [] byteArray containing = System. Text. The Encoding. The Default. The GetBytes (STR); Byte [] ByteArray = new Byte [str.length]; for (int i =0; i<str.Length; i++) { byteArray[i] = Convert.ToByte(str[i]); } Method 3; byte[] byteArray = Convert.FromBase64String(str); Method 4: byte [] byteArray containing = HttpServerUtility. UrlTokenDecode (STR);