C#-App:继承自ISerializable以进行序列化 [英] C#-App: Inherit from ISerializable for Serialization
本文介绍了C#-App:继承自ISerializable以进行序列化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
在进行序列化时,我真的需要继承ISerializable吗?
我不确定我的代码是否有问题,但是当我不从该界面继承时,我仍然可以序列化我的对象并对其进行反序列化。
Am我错过了什么?
提前谢谢。
hi everyone,
when doing serialization, do I really need to inherit from ISerializable ?
I am not sure if there is something wrong with my code but when i don''t inherit from that interface I can still serialize my object and deserialize it.
Am I missing something?
Thank you in advance.
推荐答案
我不这么认为...你不需要继承那个界面...
只需放置
< Serializable()>对于VB
[序列化()]对于C#
在一个类的顶部,将使其可序列化...
当你需要序列化一个不可序列化的类型/属性时,我认为你继承了这个接口...
欢呼!
i dont think so... you dont need to inherit that interface...
Just by placing
<Serializable()> for VB
[Serializable()] for C#
on top of a class, will make it serializable...
I think you inherit that interface when you need to serialize a type/property which is not serializable...
cheers!
你需要只有在需要创建自己的自定义序列化时才实现ISerializable。如果.Net序列化对你来说没问题,只需添加[Serializable]即可。
You need to implement ISerializable only if you need to create your own, custom serialization. If .Net serialization is ok for you, just add [Serializable] and you''re fine.
好的,现在我明白了。但是,如果我实现ISerializable,我将能够控制序列化对象的大小?
感谢您的回复
Ok, now I understand. But if I implement ISerializable will I be able to control the size of the serialized object?
Thanks for the replies
这篇关于C#-App:继承自ISerializable以进行序列化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文