可以把字元串轉換為MemoryStream。也可以把MenoryStream轉換為字元串。 下麵Insus.NET寫了幾個方法: class Bq { public string Input { get; set; } public byte[] Byte { get; set; } public ...
可以把字元串轉換為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