什么是[Serializable]属性做了ISerializable不? [英] What does the [Serializable] attribute do that ISerializable doesn't?
问题描述
可能重复:
<一href="http://stackoverflow.com/questions/2365152/whats-the-difference-between-using-the-serializable-attribute-implementing-is">What's使用Serializable属性与放大器之间的差异;实现了ISerializable?
这是什么标记一个类与<一个HREF =http://msdn.microsoft.com/en-us/library/system.runtime.serialization.iserializable.aspx相对=nofollow> 序列化
吗?例如:
What does tagging a class with Serializable
do? e.g.:
[Serializable]
public Hashtable
{
}
它是如何从类不同实现 ISerializable的
?例如:
How is it different from the class implementing ISerializable
? e.g.:
public Hashtable : ISerializable
{
}
又是怎样的是的从标签中的类为序列化和实施< A HREF =http://msdn.microsoft.com/en-us/library/system.runtime.serialization.iserializable.aspx相对=nofollow> ISerializable的
的?例如:
And how is that different from tagging the class as Serializable and implementing ISerializable
? e.g.:
[Serializable]
public Hashtable : ISerializable
{
}
的目的是什么[Serializable接口]
,而不是 ISerializable的
?
TL;博士:什么是 [Serializable接口]
推荐答案
我还以为你挂的序列化,但你没有:
I thought you'd linked to Serializable, but you didn't:
这是打上了 SerializableAttribute
默认情况下序列化,除非该类型实现了 ISerializable的在一个类型的所有公共和私营领域code>界面重写序列化进程。
All the public and private fields in a type that are marked by the
SerializableAttribute
are serialized by default, unless the type implements theISerializable
interface to override the serialization process.
和
应用,即使该类还实现了 ISerializable的
接口 SerializableAttribute
属性[...]
Apply the
SerializableAttribute
attribute even if the class also implements theISerializable
interface [...]
也就是说,序列化
属性表明这种类型的可以的序列化。 ISerializable的
表示,这种想控制的如何的这种类型的序列化。
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.
或者,换一种说法,你的问题是围绕措辞错误的方法。 SerializableAttribute
应的总是的应用(以序列化类),并且是系列化的基本的水平。 ISerializable的
添加更多(允许你写code控制过程)。
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).
这篇关于什么是[Serializable]属性做了ISerializable不?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!