C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
Tip: You can see that the BaseStream returns a reference to the MemoryStream instance that was passed to the BinaryReader.
Info: The Stream returned by BaseStream is precisely equivalent to the MemoryStream. It is, however, referenced through its base class Stream.
MemoryStreamC# program that uses BaseStream property
using System;
using System.IO;
class Program
{
static void Main()
{
using (MemoryStream memory =
new MemoryStream(File.ReadAllBytes("C:\\P.bin")))
using (BinaryReader reader = new BinaryReader(memory))
{
// Get the BaseStream Stream.
Stream baseStream = reader.BaseStream;
// The BaseStream is the MemoryStream instance.
Console.WriteLine(baseStream.Length == memory.Length);
Console.WriteLine(baseStream is MemoryStream);
}
}
}
Output
True
True