Sorting months in a list

后端 未结 8 2044
闹比i
闹比i 2020-12-19 10:00

I have a list of strings which contains months of the year. I need to be able to sort this list so the months are in order by month, not alphabetically. I have been search

8条回答
  •  情歌与酒
    2020-12-19 10:29

    You can parse month names into dates (it assumes the current year and day 1):

    monthList = monthList.OrderBy(s=> DateTime.ParseExact(s, "MMMM", new CultureInfo("en-US"))).ToList();
    

提交回复
热议问题