What is an Enum? - LessonsLearnedInDotNET/LL.NET.Enum GitHub Wiki
MSDN Definition (C#) (2016-10-20):
An enumeration type (also named an enumeration or an enum) provides an efficient way to define a set of named integral constants that may be assigned to a variable. For example, assume that you have to define a variable whose value will represent a day of the week. There are only seven meaningful values which that variable will ever store. To define those values, you can use an enumeration type, which is declared by using the enum
keyword.
So, what does that mean?
When designing a system, you often come across a domain object that is best described as one of several discrete states. The example used in the MSDN definition is days of the week.
public enum Days
{
Sunday,
Monday,
Tuesday,
Wednesday,
Thursday,
Friday,
Saturday
};
In the real world, there are 7 discrete days of the week. There is a hard set line in time when we exit the discrete state of Monday
and transition to Tuesday
. It is not possible for something to exist in Monday and Tuesday at the same time.
Calm The Brain: In case your mind is like mine and wants to shout 'time zones make it possible for people on one side of the world to exist in one day and people on the other side of the world to exist in another day!`, read the following explanation. That is true, but when data sources exist in multiple time zones, that problem can be overcome by storing the data in UTC format server-side. If all time data is stored in UTC format, then there is no offset in times relative to one another. The overlapping state cannot occur.