I have a class with a property which is an enum
The enum is
/// <summary>
/// All available delivery actions
/// </summary>
public enum EnumDeliveryAction
{
/// <summary>
/// Tasks with email delivery action will be emailed
/// </summary>
Email,
/// <summary>
/// Tasks with SharePoint delivery action
/// </summary>
SharePoint
}
When I create an instance of this class, NOWHERE in the code, do I specify the value of the enum field, but it seems to default to the first item in the enumlist, and not a null value, is this how enums work? How is it possible to ensure that the enum gets some kind of null value if it is not set, I don’t want it defaulting to the first value in the enum.
Default value for
enumtypes is0(which is by default, the first element in the enumeration). Fields of a class will be initialized to the default value.If you need to represent an unknown value in the enum, you can add an element
Unknownwith value 0. Alternatively, you could declare the field asNullable<MyEnum>(MyEnum?).