This snippet opens a binary file for reading. It deserializes the object array stored in the binary file using the BinaryFormatter Class and displays the data to the console.
using System;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
class Program
{
static void Main(string[] args)
{
Stream bStream = File.Open("file.bin", FileMode.Open);
BinaryFormatter bFormater = new BinaryFormatter();
object[] contact = (object[])bFormater.Deserialize(bStream);
for (int i = 0; i < contact.Length; i++)
{
object[] employee = (object[])contact[i];
Console.WriteLine("First Name: " + employee[0]);
Console.WriteLine("Surname: " + employee[1]);
}
Console.ReadKey();
}
}
No comments:
Post a Comment