This snippet shows how to serialize an object using the BinaryFormatter Class and save the data to a file.
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.Create);
object[] employee1 = { "John" , "Doe" };
object[] employee2 = { "Tom" , "Baker" };
object[] contacts = { employee1, employee2 };
BinaryFormatter bFormater = new BinaryFormatter();
bFormater.Serialize(bStream, contacts);
Console.ReadKey();
}
}
No comments:
Post a Comment