How to list all month names, e.g. for a combo?

后端 未结 16 1024
栀梦
栀梦 2020-12-23 14:38

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?

16条回答
  •  滥情空心
    2020-12-23 14:49

    I did in the following way: (it's possible to set the culture)

    var months = Enumerable.Range(1, 12).Select(i => 
        new
        {
            Index = i,
            MonthName = new CultureInfo("en-US").DateTimeFormat.GetAbbreviatedMonthName(i)
        })
        .ToDictionary(x => x.Index, x => x.MonthName);
    

提交回复
热议问题