I have this enum:
public enum TimePeriod
{
Day = DateTime.Now.AddDays(-1),
Week = DateTime.Now.AddDays(-7),
Month = DateTime.Now.AddMonths(-1),
AllTime = DateTime.Now
}
but cant do
(DateTime)timePeriod
how can i get the date given an enum?
In C#, the default underlying type for an
enumisint, and unfortunately is only support basic data types likeint,short,uintand so on. Therefore, storing theDateTimesinside anenumis not possible in .NET.You can of course make a static class with static properties that expose the
DateTimesyou need instead of making it like anenumlike this:And use it like this: