C#是或不是[Serializable]? [英] C# To be, or not to be [Serializable]?

查看:229
本文介绍了C#是或不是[Serializable]?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello codeproject,



我有一个项目,我不知道是否应该使我的枚举可序列化,或者它是否会影响我的使用项目。

这是它的工作原理:



  public  枚举 ColorOfFood {values} 

[可序列化]
public class 食品
{
私有 string 名称;
私有 ColorOfFood颜色;
}

[可序列化]
public class FoodList {List< Food> }







我的最终目标是使用binairyFormatter保存Food类的值。

我应该能够保存并检索它们。 (并且当然使用它们)



感谢您的问候,

Bert

解决方案

< blockquote>枚举本质上是可序列化的(它们是常量整数值)。你不必费心:)

为什么不做一个简单的琐碎测试来检查呢?

亲切的问候。


Hello codeproject,

I have a project and I don't know if I should make my enum serializable or if it won't affect the use of my project.
This is how it works:

public enum ColorOfFood { values }

[Serializable]
public class Food
{
   private string name;
   private ColorOfFood color;
}

[Serializable]
public class FoodList { List<Food> }




My ultimate goal is to save both the values of the class Food using a binairyFormatter.
I should be able to save and retrieve them. (And ofcourse use them)

Thanks in regards,
Bert

解决方案

Enumerations are serializable by nature (they are constant integer values). You don't have to bother :)
Why not just making a simple trivial test to check it?
Kind regards.


这篇关于C#是或不是[Serializable]?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆