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);
}
}
|