可以把字符串转换为MemoryStream。也可以把MenoryStream转换为字符串。
下面Insus.NET写了几个方法:
class Bq { public string Input { get; set; } public byte[] Byte { get; set; } public MemoryStream MemStream { get; set; } public byte[] GetByte() { return Encoding.ASCII.GetBytes(Input); } public MemoryStream GetMemoryStream() { byte[] byteArray = Byte; return new MemoryStream(byteArray); } public string GetString() { StreamReader reader = new StreamReader(MemStream); return reader.ReadToEnd(); } }
Source Code
控制台测试以上的方法:
class Program { static void Main(string[] args) { Bq objBq = new Bq(); objBq.Input = "Hello Insus.NET"; byte[] Bytes = objBq.GetByte(); objBq.Byte = Bytes; MemoryStream ms = objBq.GetMemoryStream(); objBq.MemStream = ms; string output = objBq.GetString(); Console.WriteLine(output); } }
Source Code
點擊查看更多內(nèi)容
為 TA 點贊
評論
評論
共同學習,寫下你的評論
評論加載中...
作者其他優(yōu)質(zhì)文章
正在加載中
感謝您的支持,我會繼續(xù)努力的~
掃碼打賞,你說多少就多少
贊賞金額會直接到老師賬戶
支付方式
打開微信掃一掃,即可進行掃碼打賞哦