服务说明是必需的 [英] Serilization Explanation is Required
本文介绍了服务说明是必需的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
什么是序列化?以及如何实施?任何人都可以借助最好理解的例子来解释它吗?
What is serialization? and how it can be implemented? can anyone explain it with help of best understandable example?
推荐答案
序列化是将在内存中表示的对象转换为平面格式的过程。通常以文本格式或字节数组存储。
序列化需要双向 - 允许读者从平面格式重新创建对象。
例如:
serialization is the process of translating an object that is represented in memory, into a "flat" format that can be stored, usually in a text format, or a byte array.
the serialization needs to be two way- to allow a reader to recreate the object from the flat format.
for example:
int number = 5;
string serializedText = SomeSerializationUtility.SerializeToString(number);
int number2 = SomeSerializationUtility.DeserializeFromString(serializedText );
Asset.AreEqual(number, number2);
当然,序列化时事情变得复杂得多具有多个属性和内部状态的对象,以及可能本身就是复杂类型的内部属性。
所以例如:
of course things get a lot more complicated when serializing objects that have multiple properties, and internal states, and perhaps inner properties that are themselves complex types.
so for example:
public class MyData
{
public string Text;
public int Number;
public List<double> data;
}
</double>
可以用以下XML格式表示:
could be represented in the following XML format:
<mydata>
<text type="string">blabla</text>
<number type="int">5</number>
<data type="List<double>"><item>0.0</item></data>
</mydata>
你应该能够很容易地看到这些数据是如何在XML元素和类属性之间映射的。
and you should be able to easily see how this data is mapped between XML elements and class properties.
我认为你应该尝试阅读像 this [ ^ ]。
很好的例子。
快乐编码。
I think that you should try reading something like this[^] on MSDN.
Nice example there.
Happy coding.
这篇关于服务说明是必需的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文