Example

 using System; using System.IO; namespace Samples { public class MemoryStreamSample { public static void Main() { byte[] bytes = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; using(MemoryStream ms = new MemoryStream(bytes, 0, bytes.Length)) { DisplayInformationAboutStream(ms); bytes = new Byte[5]; ms.Read(bytes, 0, bytes.Length); foreach(Byte b in bytes) Console.WriteLine(b); } using(MemoryStream ms = new MemoryStream(256)) { ms.SetLength(10); DisplayInformationAboutStream(ms); byte[] bytes1 = ms.GetBuffer(); ms.SetLength(1024); DisplayInformationAboutStream(ms); Byte[] bytes2 = ms.GetBuffer(); Console.WriteLine("Are the buffers the same: {0}", Object.ReferenceEquals(bytes1, bytes2)); } } public static void DisplayInformationAboutStream( MemoryStream ...

Get .NET Framework Standard Library Annotated Reference, Volume 1: Base Class Library and Extended Numerics Library now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.