
How can you use the BaseStream property on types to get information about the underlying buffer? BaseStream is available on derived Stream instances.
This C# article demonstrates the BaseStream instance property.

First, this program uses two System.IO objects: the MemoryStream, which stores the bytes in the specific file; and the BinaryReader, which exposes the BaseStream property. The two using statements enclose a block of code that uses the BinaryReader object. You can see that the BaseStream returns a reference to the MemoryStream instance that was passed to the BinaryReader.
Program that uses BaseStream property [C#]
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
TrueType of BaseStream. You can also see in the output of the program that the Stream returned by BaseStream is precisely equivalent to the MemoryStream. It is, however, referenced through its base class Stream.
MemoryStream Use
The BaseStream property is defined on several different types, including BinaryWriter, BinaryReader, StreamWriter, and StreamReader—types that act upon underlying streams. The best reason to use BaseStream is if your program's design doesn't allow you to access the base stream directly.
BinaryWriter Tutorial BinaryReader Tutorial Using StreamWriter Using StreamReaderIn other words, if you design a method that receives a BinaryReader parameter directly, you can call BaseStream to get the underlying Stream reference. In the example shown above, we could easily access the MemoryStream directly; this is not always possible.

The BaseStream property is useful when using classes that act upon underlying Streams. Often, you will need to get a reference to the original Stream to get its total Length or type. This can be useful when developing methods that receive types that have underlying Streams.
File Handling