Альтернативный подход, если вы все еще хотите использовать Enums
в течение месяцев, - это создать класс расширения:
public enum Month
{
January = 1,
February = 2,
March = 3,
April = 4,
May = 5,
June = 6,
July = 7,
August = 8,
September = 9,
October = 10,
November = 11,
December = 12
}
public static class MonthExtensions
{
private static readonly Dictionary<int, string> _seasons = new Dictionary<int, string>
{
{1, "Spring" },
{2, "Summer" },
{3, "Autumn" },
{4, "Winter" }
};
private static readonly Dictionary<int, string> _names = new Dictionary<int, string>
{
{1, "January"},
{2, "February"},
{3, "March"},
{4, "April"},
{5, "May"},
{6, "June"},
{7, "July"},
{8, "August"},
{9, "September"},
{10, "October"},
{11, "November"},
{12, "December"}
};
private static readonly Dictionary<int, int> _seasonMap = new Dictionary<int, int>
{
{1, 4},
{2, 4},
{3, 1},
{4, 1},
{5, 1},
{6, 2},
{7, 2},
{8, 2},
{9, 3},
{10, 3},
{11, 3},
{12, 4}
};
public static string GetSeason(int monthIndex)
=> ((Month)monthIndex).Season();
public static IEnumerable<string> GetSeasons(IEnumerable<int> monthIndexes)
=> monthIndexes.Select(i => GetSeason(i));
public static string Season(this Month month)
=> _seasons[_seasonMap[Index(month)]];
public static int Index(this Month month)
=> (int)month;
public static string Name(this Month month)
=> _names[Index(month)];
}