I have a List of months of type "String". I am trying to parse these into a DateTime object so I can sort/order the months by current month
List<String> test = new List<String>(Model.Attributes.Select(p => p.Title).ToList());
var sortedMonths = test;
sortedMonths = sortedMonths
.Select(x => new { Name = x, Sort = DateTime.ParseExact(x.ToString(), "MMMM", System.Globalization.CultureInfo.CurrentCulture) })
.OrderBy(x => x.Sort.Month)
.Select(x => x.Name)
.ToList();
I am filling the List test and after debugging it shows it is filled with the months. However I keep getting an error when I try to parse them. I've tried to manually input a string month in the place of "x" to know for sure if the format works, and it does. I can't figure this out...
EDIT: I've also already tried manually setting the CurrentCulture.