C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
Note: You can pass instances of FileStream and MemoryStream to this method. We use the Stream abstraction to perform certain tasks.
MemoryStreamFileStreamFile.OpenC# program that uses Stream type
using System;
using System.IO;
class Program
{
    static void Main()
    {
        FileStream stream1 = File.Open("C:\\a", FileMode.Open);
        Print(stream1);
        MemoryStream stream2 = new MemoryStream(new byte[1234]);
        Print(stream2);
    }
    static void Print(Stream stream)
    {
        Console.WriteLine(stream.Length);
        Console.WriteLine(stream.Position);
    }
}
Output
5469165
0
1234
0
Tip: This means you can avoid having duplicate methods (such as one that receives FileStream and one that receives MemoryStream).
But: This helps us understand the architecture of Stream types in the .NET Framework.