Alex Rivera | Logout

Initial Value of an Enum

Asked 2009-07-22T13:49:27.770
69

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.

Edit
Report

1 Answer

1

You can start your enums at any value (such as 1), but when they represent a lookup value in a Database, you generally want them to match up.

I generally declare the first Enum as None ( = 0) when it makes sense to do so, as per the .Net Framework Design guidelines.

answered 2009-07-22T13:55:51.413

Your Answer