using System.IO; int number = 0; using (BinaryReader reader = new BinaryReader(File.Open("data.bin", FileMode.Open))) { number = reader.ReadInt32(); } Console.WriteLine(number);
using System.IO; int[] numbers = new int[10]; using (BinaryReader reader = new BinaryReader(File.Open("data.bin", FileMode.Open))) { for (int i = 0; i < 10; i++) { numbers[i] = reader.ReadInt32(); } } foreach (int number in numbers) { Console.WriteLine(number); }This code reads an array of 10 integers from a binary file called "data.bin". The values are read using a loop and the ReadInt32() method of the BinaryReader class. Finally, the values are printed to the console. The package library that includes the BinaryReader class is the System.IO namespace.