Question about Serialization.

Posted on 2005-04-27
Last Modified: 2010-04-16
I have a question to the sample code in MSDN regarding Serialization:

In the code:
BinaryFormatter formatter = new BinaryFormatter();
formatter.Serialize(fs, addresses);

But the Serialize method is a virtual overloaded method. And I couldn't find the real implementation of the Serialize().

So where is the real implementation of the Serialize() method?

I think my question came from not knowing level details of the Serialization. Anybody can clarify this? Many thanks!
Question by:heyday2004
    LVL 9

    Accepted Solution

    I'm not quite sure I understand what your question is.  You're saying the BinaryFormatter.Serialize() method is overloaded?  That just means there is more than one way to call the method (more than one acceptable signature).  Either one of them is the "real implementation" of the Serialize() method.  The BinaryFormatter class implements two interfaces: IRemotingFormatter and IFormatter.  The specifications for these interfaces require the class to implement a Serialize() method.
    LVL 20

    Assisted Solution

    The implementation of the Serialize method is in the BinaryFormatter class. It uses the binary presentation of the argument to serialize it in the underlying stream. The objects to be serialized must always be marked with the [Serializable] attribute.
    LVL 4

    Assisted Solution

    To add to TheAvenger's comment. As an option You can choose how you want to serialize your class. For that you need to implement ISerializable interface.

    One more thing. The virtual method means it will(should) have default implementation however you can give your own implementation is you want to do that. so BinaryFormatter already has the implementation but if u want to use your own formater you can override Serialize method.

    Nachiket Shah

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Article by: Najam
    Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
    Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now