定義string變量為str,內(nèi)存流變量為ms,比特?cái)?shù)組為bt
1.字符串轉(zhuǎn)比特?cái)?shù)組
(2)byte[] bt=Convert.FromBase64String("字符串");
2.字符串轉(zhuǎn)流
(2)MemoryStream ms=new MemoryStream(Convert.FromBase64String("字符串"));
3.流轉(zhuǎn)比特?cái)?shù)組
(2)MemoryStream ms=new MemoryStream();ms.Write(bt,0,ms.Length);
4.流轉(zhuǎn)字符串
(2)string str=System.Text.Encoding.Default.GetString(ms.ToArray());
5.比特?cái)?shù)組轉(zhuǎn)字符串
(2)string str=Convert.ToBase64String(bt);
6.比特?cái)?shù)組轉(zhuǎn)流
(2)MemoryStream ms=new MemoryStream();ms.Read(bt,0,bt.Length);
總結(jié):可以看出byte[]在字符串string和流MemoryStream之間轉(zhuǎn)換起到過渡的作用,string和MemoryStream轉(zhuǎn)換都要先轉(zhuǎn)換成byte[]。



















