Translation of C # string and memory stream MemoryStream and bit array byte[] _c# tutorial

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.