Possible Duplicate:
What's the difference between using the Serializable attribute & implementing ISerializable?
标记 class 有什么作用?与 Serializable
做?例如:
[Serializable]
public Hashtable
{
}
它与 class 有何不同?实现 ISerializable
?例如:
public Hashtable : ISerializable
{
}
那与标记 class 有何不同?作为Serializable并实现 ISerializable
?例如:
[Serializable]
public Hashtable : ISerializable
{
}
[Serializable]
相对于 ISerializable
的目的是什么?
tl;dr:什么是[Serializable]
?
我以为你会链接到 Serializable ,但你没有:
All the public and private fields in a type that are marked by the SerializableAttribute
are serialized by default, unless the type implements the ISerializable
interface to override the serialization process.
和,
Apply the SerializableAttribute
attribute even if the class also implements the ISerializable
interface [...]
即 Serializable
属性表示该类型可以被序列化。 ISerializable
表示该类型想要控制如何该类型被序列化。
或者,换句话说,您的问题措辞不当。 SerializableAttribute
应始终 应用于(可序列化的类),并且是序列化的“基本”级别。 ISerializable
添加了更多内容(通过允许您编写代码来控制进程)。