using System.IO; MemoryStream memoryStream = new MemoryStream(); // Use the memoryStream... memoryStream.Close();
using System.IO; using (MemoryStream memoryStream = new MemoryStream()) { // Use the memoryStream... }In this example, we use a using statement to automatically dispose of the MemoryStream object and release its resources. Package library: System.IO.MemoryStream is a part of the .NET standard library, which is included in the .NET Framework, .NET Core, and Xamarin.