Deserialize Object

image_pdfimage_print
   
  

using System;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;
[Serializable]
public class BookRecord {
    public String title;
    public int asin;

    public BookRecord(String title, int asin) {
        this.title = title;
        this.asin = asin;
    }
}
public class DeserializeObject {
    public static void Main() {
        FileStream streamIn = new FileStream(@"book.obj", FileMode.Open);
        BinaryFormatter bf = new BinaryFormatter();
        BookRecord book = (BookRecord)bf.Deserialize(streamIn);
        streamIn.Close();
        Console.Write(book.title + " " + book.asin);
    }
}

   
     


This entry was posted in File Stream. Bookmark the permalink.