Use Serializable attribute to mark a class : Serialization : File Stream C# Source Code


Custom Search

C# Source Code » File Stream » Serialization »

 

Use Serializable attribute to mark a class








    
 

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 SerializeObject {
    public static void Main() {
        BookRecord book = new BookRecord("title",123456789);
        FileStream stream = new FileStream(@"book.obj",FileMode.Create);

        BinaryFormatter bf = new BinaryFormatter();
        bf.Serialize(stream, book);
        stream.Close();
    }
}

 
    
   
  
   







HTML code for linking to this page:

Follow Navioo On Twitter

C# Source Code

 Navioo File Stream
» Serialization