using (var reader = new BinaryReader(File.OpenRead("file.bin"))) { var value = reader.ReadInt32(); var str = reader.ReadString(); var dbl = reader.ReadDouble(); Console.WriteLine("{0} {1} {2}", value, str, dbl); }
using (var client = new TcpClient("localhost", 1234)) using (var stream = client.GetStream()) using (var reader = new BinaryReader(stream)) { var value = reader.ReadInt32(); Console.WriteLine(value); }This example demonstrates how to read binary data from a network stream using a BinaryReader object. It creates a TCP client and connects to the local host on port 1234. It then reads an integer value from the network stream using the BinaryReader object. Package library: System.IO.