Defines a string variable of str, the memory rheology is MS, and the bit array is BT
1. String-bit array
Copy Code code as follows:
(1) byte[] Bt=system.text.encoding.default.getbytes ("string");
(2) byte[] bt=convert.frombase64string ("string");
2. String flow
Copy Code code as follows:
(1) MemoryStream ms=new MemoryStream (System.Text.Encoding.Default.GetBytes ("string"));
(2) MemoryStream ms=new MemoryStream (convert.frombase64string ("string"));
3. Flow bit Array
Copy Code code as follows:
(1) byte[] Bt=ms. ToArray ();
(2) MemoryStream ms=new MemoryStream (), Ms. Write (Bt,0,ms. Length);
4. Flow string
Copy Code code as follows:
(1) String str=convert.tobase64string (Ms. ToArray ());
(2) String str=system.text.encoding.default.getstring (Ms. ToArray ());
5. Bit array Turn string
Copy Code code as follows:
(1) string str=system.text.encoding.default.getstring (BT);
(2) string str=convert.tobase64string (BT);
6. Bit array flow
Copy Code code as follows:
(1) MemoryStream ms=new MemoryStream (BT);
(2) MemoryStream ms=new MemoryStream (), Ms. Read (BT,0,BT. Length);
Summary: you can see that byte[] transitions between string strings and stream MemoryStream, and string and MemoryStream conversions are converted to byte[first.