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

后端 未结 16 983
栀梦
栀梦 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 15:12

    public IEnumerable Months
    {
      get
      {
        return Enumerable.Range(1, 12).Select(x => new SelectListItem
        {
          Value = x.ToString(),
          Text = DateTimeFormatInfo.CurrentInfo.GetMonthName(x)
        });
      }
    }
    

提交回复
热议问题