At the moment I\'m creating a DateTime for each month and formatting it to only include the month.
Is there another or any better way to do this?
A way to retrieve a dynamic culture specific list of month names in C# with LINQ.
ComboBoxName.ItemsSource=
System.Globalization.CultureInfo.
CurrentCulture.DateTimeFormat.MonthNames.
TakeWhile(m => m != String.Empty).ToList();
OR
In this example an anonymous object is created with a Month and MonthName property
var months = CultureInfo.CurrentCulture.DateTimeFormat.MonthNames
.TakeWhile(m => m != String.Empty)
.Select((m,i) => new
{
Month = i+1,
MonthName = m
})
.ToList();
PS: We use the method TakeWhile because the MonthNames array contains a empty 13th month.