Struct serialization

Posted on 2006-05-23
Last Modified: 2008-03-10
What do I need to make a struct serializable? Do I need to derrive from ISerializable?

Question by:gromul
    LVL 44

    Assisted Solution

    Hi gromul,

    you need to add the [Serializable] attrribute like

      public struct MyAccount {
        public int AccountNumber;
        public string CustomerName;
        public float Balance;

    for more details

    share what you know, learn what you don't
    LVL 13

    Accepted Solution

    As far as implementeting ISerializable it depends.  The Serializable() attribute is for xml serialization which by default will only serialize public fields.  If you need to serialize private members then that is when you implement ISerializable.  However with custom serialization your only left with SoapFormatting or BinaryFormatting.  There is an IXmlSeriazable interface but its marked as "do not use" from Microsoft which means it could change and is unsupported.

    Author Comment


    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    Join & Write a Comment

    Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
    This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    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.

    754 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

    17 Experts available now in Live!

    Get 1:1 Help Now