Enum is Reference Type or Value Type?

user1318951 picture user1318951 · Jan 28, 2013 · Viewed 35.5k times · Source

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?

Answer

Jon Skeet picture Jon Skeet · Jan 28, 2013

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?.