枚举是引用类型还是值类型? [英] Enum is Reference Type or Value Type?

查看:592
本文介绍了枚举是引用类型还是值类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用枚举属性在我的的EntityFramework 的5类, 但在数据库中该字段为空。视觉工作室给这个属性必须是一个可为空性的错误。我的问题是:是枚举引用类型或值类型

I used Enum property in my EntityFramework 5 class, but in the database this field is nullable. Visual studio gives the error that this property must be a nullable property. My question is: is Enum a reference type or a value type?

推荐答案

System.Enum 是引用类型,但是任何的的具体的枚举类型是值类型。以同样的方式, System.ValueType 是引用类型,但所有类型从它继承(超过 System.Enum )是值类型。

System.Enum is a reference type, but any specific enum type is a value type. In the same way, System.ValueType is a reference type, but all types inheriting from it (other than System.Enum) are value types.

所以,如果你有一个枚举和你想有一个可为空的属性,你需要的属性类型为富?

So if you have an enum Foo and you want a nullable property, you need the property type to be Foo?.

这篇关于枚举是引用类型还是值类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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