Possible Duplicate:
What's the difference between using the Serializable attribute & implementing ISerializable?
What does tagging a class with Serializable do? e.g.:
[Serializable]
public Hashtable
{
}
How is it different from the class implementing ISerializable? e.g.:
public Hashtable : ISerializable
{
}
And how is that different from tagging the class as Serializable and implementing ISerializable? e.g.:
[Serializable]
public Hashtable : ISerializable
{
}
What is the purpose of [Serializable] as opposed to ISerializable?
tl;dr: What is [Serializable]?
I thought you'd linked to Serializable, but you didn't:
All the public and private fields in a type that are marked by the
SerializableAttributeare serialized by default, unless the type implements theISerializableinterface to override the serialization process.
and,
Apply the
SerializableAttributeattribute even if the class also implements theISerializableinterface [...]
That is, the Serializable attribute indicates that this type can be serialized. ISerializable indicates that this type wants to control how this type is serialized.
Or, to put it another way, your question is phrased the wrong way around. SerializableAttribute should always be applied (to serializable classes), and is the "basic" level of serialization. ISerializable adds more (by allowing you to write code to control the process).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With