Enum fields are initialized to zero; a, if you do not specify values ββin the enumeration, they start from zero ( Email = 0 , SharePoint=1 , etc.).
Thus, by default, any field that you initialize will be Email . For such cases, it is relatively convenient to add None=0 or, alternatively, use Nullable<T> ; i.e.
/// <summary> /// All available delivery actions /// </summary> public enum EnumDeliveryAction { /// <summary> /// Not specified /// </summary> None, /// <summary> /// Tasks with email delivery action will be emailed /// </summary> Email, /// <summary> /// Tasks with SharePoint delivery action /// </summary> SharePoint }
You must also be sure that you will never handle your last expected default value; i.e.
switch(action) { case EnumDeliveryAction.Email; RunEmail(); break; default: RunSharePoint(); break; }
it should be:
switch(action) { case EnumDeliveryAction.Email; RunEmail(); break; case EnumDeliveryAction.SharePoint; RunSharePoint(); break; default: throw new InvalidOperationException( "Unexpected action: " + action); }
Marc Gravell Jul 22 '09 at 13:53 2009-07-22 13:53
source share