using System.IO; // Read object from file using (FileStream fs = new FileStream("data.bin", FileMode.Open)) { BinaryReader br = new BinaryReader(fs); MySerializableObject obj = (MySerializableObject)br.ReadSerializable(); }
using System.IO; // Read object from network stream using (NetworkStream ns = client.GetStream()) { BinaryReader br = new BinaryReader(ns); MySerializableObject obj = (MySerializableObject)br.ReadSerializable(); }In this example, we are reading a serialized object from a network stream using the BinaryReader class. The ReadSerializable method is used to deserialize the object and cast it to our custom class MySerializableObject. This can be useful when exchanging objects between networked applications. The System.IO namespace containing the BinaryReader class is part of the .NET Framework Class Library.